[Updated] Goldman Sachs Aptitude Test Questions and Answers
Practice List of TCS Digital Coding Questions !!!
Take 50+ FREE!! Online Data Interpretation Mock test to crack any Exams.

C Programming :: Declarations and Initializations - Discussion

Home > C Programming > Declarations and Initializations > MCQs Questions Discussion

496 / 54

What will be the result of the following program?

#include <stdio.h>
int main()
{
static int i;
int j;
for(j=0;j<10;j++)
{
i= i+2;
i = i-j;
}
printf("%d",i);
return 0;
}

A25

B-25

C20

D-20

ENone of these

Answer: Option (Login/Signup)

Show Explanation

i=i+2 will be 0+2 =2;

i = i - j will be 2-0 = 2;

second iteration i=2

j=1;

i=i+2 will be 4

i =i-j will be 4-1 =3

third iteration i=3

j=2;

i=i+2 will be 5

i= i-j will be 5-2 =3

fourth iteration i=3

j=3;

i=i+2 will be 5

i= i-j will be 5-3 =2

fifth iteration i=2

j=4;

i=i+2 will be 4

i =i-j will be 4-4=0

sixth iteration i=0

j=5;

i=i+2 will be 2

i= i-j will be 2-5 =-3

seventh iteration i=-3

j=6;

i=i+2 will be -1

i =i-j will be -1-6 =-7

eighth iteration i=-7

j=7;

i=i+2 will be -5

i =i-j will be -5-7 =-12

ninth iteration i=-12

j=8;

i=i+2 will be -10

i =i-j will be -10-8 =-18

tenth iteration i=-18

j=9;

i=i+2 will be -16

i =i-j will be -16-9 =-25

printf("%d", i); will be -25



Asked In :: TCS

Post Your Answer Here:     

Reply    
Rate This: +1 -0 +
    Report


Report Error

Please Login First Click Here

Reply    
Rate This: +0 -0
    Report


Report Error

Please Login First Click Here

Reply    
Rate This: +0 -0
    Report


Report Error

Please Login First Click Here

Reply     |    Rate This: +0 -0      |     Report     



Report Error