how does the for loop work actually..suppose for the
following program how it ll work plz explain to me
for(i=5;i>=0;i--)
prinf(i--);

Answers were Sorted based on User's Feedback



how does the for loop work actually..suppose for the following program how it ll work plz explain ..

Answer / abhishek roy

Yes there is syntax error in printf statement but if write
printf("%d",i--)then The output for the given for loop is
5 3 1.

it is 100 % write....

Is This Answer Correct ?    1 Yes 0 No

how does the for loop work actually..suppose for the following program how it ll work plz explain ..

Answer / hope

Here is the correct answer. I have written this program
into my program. I run it and got the following output:
5
4
3
2
1
0

Is This Answer Correct ?    2 Yes 3 No

how does the for loop work actually..suppose for the following program how it ll work plz explain ..

Answer / subha raman

The operation in for-loop is "i--"..so it will print the
decremented value first..hence the output will be:
4
3
2
1
0

Is This Answer Correct ?    14 Yes 16 No

how does the for loop work actually..suppose for the following program how it ll work plz explain ..

Answer / sarvagya sharma

all the above answers are wrong i have written this program
into turbo c++ and here is what i got the output
5
4
3
2
1
0

Is This Answer Correct ?    2 Yes 4 No

how does the for loop work actually..suppose for the following program how it ll work plz explain ..

Answer / sadheesh kumar.s, vlbjcas,cova

the correct answer is
4
3
2
1
0

Is This Answer Correct ?    4 Yes 9 No

how does the for loop work actually..suppose for the following program how it ll work plz explain ..

Answer / preshit

o/p will b
4 2 0
bcoz first i=5 ok then condition after taht ok so printf
will decrement i, so o/p 4
then it decrement it twice for 2 times

OR
it will give syntax error if printf(i--)is wrong

Is This Answer Correct ?    0 Yes 7 No

how does the for loop work actually..suppose for the following program how it ll work plz explain ..

Answer / sindhura

it gives an error ,because prinf statement not given
correctly.if the printf statement is given as printf("\t%d",i--)
then the output of the prgm will be,
5 4 3 2 1 0

Is This Answer Correct ?    2 Yes 10 No

how does the for loop work actually..suppose for the following program how it ll work plz explain ..

Answer / subha raman

sorry..please ignore the above answer..
the operation is "i--" =>post decrement,fist do the
operation and then decrement.
so the output will be:
5

Is This Answer Correct ?    5 Yes 14 No

how does the for loop work actually..suppose for the following program how it ll work plz explain ..

Answer / shikhar

The answer given by preshit is absolutely correct...Lets
see how ,we have >>>
for(i=5;i>=0;i--)
Now we can write this all as :

//start of program

STEP 1 : for(i=5;i>=0;)
{
STEP 2 : prinf(i--);
STEP 3 : i--;
}
//end of program

TT : now the loop will start with i=5
when control reaches printf it firstly executes its
internal statement i.e i-- and then prints i-1(i.e 4) and
it Reduces i by 1.i becomes 3
NOW once again STEP 1 :go to TT

OUTPUT :
4
2
0

Is This Answer Correct ?    2 Yes 14 No

Post New Answer

More C Interview Questions

is it possible to change the default calling convention in c ?

1 Answers   Aptech,


How can you draw circles in C?

0 Answers   Accenture,


How will you write a code for accessing the length of an array without assigning it to another variable?

0 Answers  


Write an implementation of “float stringToFloat(char *str).” The code should be simple, and not require more than the basic operators (if, for, math operators, etc.). • Assumptions • Don’t worry about overflow or underflow • Stop at the 1st invalid character and return the number you have converted till then, if the 1st character is invalid return 0 • Don’t worry about exponential (e.g. 1e10), instead you should treat ‘e’ as an invalid character • Write it like real code, e.g. do error checking • Go though the string only once • Examples • “1.23” should return 1.23 • “1a” should return 1 • “a”should return 0

6 Answers   Qualcomm,


How can you determine the size of an allocated portion of memory?

0 Answers   Aspire, Infogain,


Implement a function that returns the 5th element from the end in a singly linked list of integers in one pass.

11 Answers   Microsoft,


How do we declare variables in c?

0 Answers  


How do you determine if a string is a palindrome?

1 Answers  


Explain union. What are its advantages?

0 Answers  


In c language can we compile a program without main() function?

0 Answers  


What does return 1 means in c?

0 Answers  


Write a C program to accept a matrix of any size. Find the frequency count of each element in the matrix and positions in which they appear in the matrix

0 Answers   CLG,


Categories