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
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 |
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 |
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 |
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 |
Answer / sadheesh kumar.s, vlbjcas,cova
the correct answer is
4
3
2
1
0
| Is This Answer Correct ? | 4 Yes | 9 No |
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 |
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 |
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 |
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 |
write a program in c language for the multiplication of two matrices using pointers?
define c
can we store values and addresses in the same array? explain
write C code to reverse a string such that if i/p is "abc defg hij klmno pqrs tuv wxyz" and the o/p should be "cba gfed jih onmlk srqp vut zyxw"
Why the use of alloca() is discouraged?
Write an efficient algo and C code to shuffle a pack of cards.. this one was a feedback process until we came up with one with no extra storage.
an expression contains relational operators, assignment operators, and arithmatic operstors. In the absence of parentheses, they will be evaluated in which of the following order a) assignment, relational, arithematic b) arithematic, relational, assignment c) relational, arithematic, assignment d) assignment, arithematic, relational
Compare and contrast compilers from interpreters.
2)#include<iostream.h> main() { printf("Hello World"); } the program prints Hello World without changing main() the o/p should be intialisation Hello World Desruct the changes should be a)iostream operator<<(iostream os, char*s) os<<'intialisation'<<(Hello World)<<Destruct b) c) d)none of the above
a number is perfect if it is equal to the sum of its proper divisor.. 6 is perfect number coz its proper divisors are 1,2 and three.. and 1+2+3=6... a number is deficient if the sum of its proper divisor is less than the number.. sample: 8 is deficient, coz its proper divisors are 1,2 and 4, and 1+2+4=7. abundant number, if the sum of its proper divisor is greater than the number.. sample..12 is abundant coz 1+2+3+4+6=16 which is geater than 12. now write a program that prompts the user for a number, then determines whether the number is perfect,deficient and abundant..
What is the difference between ++a and a++?
Does c have an equivalent to pascals with statement?