ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
info       Did you received any Funny E-Mails from your Friends and like to share with rest of our friends? Yeah!! you can post that stuff   HERE
Google
 
Categories  >>  Software  >>  Programming Languages  >>  C
 
 


 

 
 C interview questions  C Interview Questions
 C++ interview questions  C++ Interview Questions
 VC++ interview questions  VC++ Interview Questions
 Delphi interview questions  Delphi Interview Questions
 Programming Languages AllOther interview questions  Programming Languages AllOther Interview Questions
Question
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--);
 Question Submitted By :: Aparna
I also faced this Question!!     Rank Answer Posted By  
 
  Re: 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--);
Answer
# 1
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 ?    3 Yes 7 No
Subha Raman
 
  Re: 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--);
Answer
# 2
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 ?    2 Yes 5 No
Subha Raman
 
 
 
  Re: 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--);
Answer
# 3
both of the answers are wrong
 
Is This Answer Correct ?    5 Yes 0 No
Aparna
 
  Re: 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--);
Answer
# 4
the correct answer is
4
3
2
1
0
 
Is This Answer Correct ?    0 Yes 5 No
Sadheesh Kumar.s, Vlbjcas,cova
 
  Re: 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--);
Answer
# 5
All above answers are wrong.
Correct answer is 
5
3
1.
This is because the value "i" is decremented twice (once in 
the loop and second time in the printf() function).
 
Is This Answer Correct ?    7 Yes 1 No
Ratan
 
  Re: 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--);
Answer
# 6
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 ?    1 Yes 5 No
Sindhura
 
  Re: 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--);
Answer
# 7
ur printf syntax is wrong so..u'll will get syntax error
 
Is This Answer Correct ?    3 Yes 1 No
Vishnu
 
  Re: 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--);
Answer
# 8
The output for the given for loop is
5 3 1.
why because...
first the value of (i=5)>=0,so 5 is printed.After that i 
value is decremented because of i-- in the printf() and 
again i value is decremented as specified in for loop.
Now the value of i=3.
Again the loop will be continued untill the value of i 
becomes 0.
 
Is This Answer Correct ?    4 Yes 1 No
Manju
 
  Re: 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--);
Answer
# 9
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 4 No
Preshit
 
  Re: 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--);
Answer
# 10
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 ?    1 Yes 7 No
Shikhar
 
  Re: 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--);
Answer
# 11
The correct answer is 

5
3
1

because

in for loop "i--" statement is there and again in printf
statement "i--" is there.
 
Is This Answer Correct ?    6 Yes 1 No
Suresh Reddy
 
  Re: 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--);
Answer
# 12
It will give compilatiin error "warning: passing argument 1
of âprintfâ makes pointer from integer without a cast",
because the syntax of printf is not right.
And it would have been printf("%d",i--);
Then correct answer is 531.


This is the correct answer rest all are wrong.[:)]
 
Is This Answer Correct ?    4 Yes 2 No
Rima
 
  Re: 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--);
Answer
# 13
5
3
1
 
Is This Answer Correct ?    7 Yes 0 No
Jinga Lala
 
  Re: 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--);
Answer
# 14
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 ?    1 Yes 2 No
Sarvagya Sharma
 
  Re: 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--);
Answer
# 15
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 ?    1 Yes 1 No
Hope
 
  Re: 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--);
Answer
# 16
syntax error.... in prinf...but it should be corrected then
the result will be 
5
3
1
Note ... 
in first run I=5; printf(i--) print I which is 5 and store 4
in i.
in second run i-- means 4-1=3 then printf(i--) print 3 and
store 2 in i.
in third run... i-- measn 2-1=1 then printf(i--) print 1 and
store 0 in i.
then decreament statement i-- store 1=-1 and when compare
-1>=0 become false and goto next statement after that loop.
 
Is This Answer Correct ?    0 Yes 0 No
Devi Dayal Jangra
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
what is the use of #pragma pack, wer it is used? Wipro1
which of the following statements is incorrect a.typedef struct new{ int n1; char n2; } DATA; b.typedef struct { int n3; char *n4; }ICE; c.typedef union { int n5; float n6; } UDT; d.#typedef union { int n7; float n8; } TUDAT; TCS5
Find string palindrome 10marks Honeywell5
why TCS selected more student in the software field from all institution. TCS3
what is difference b/w extern & volatile variable?? Teleca2
macros and function are related in what aspect? a)recursion b)varying no of arguments c)hypochecking d)type declaration HCL8
main() { char *ptr = "Ramco Systems"; (*ptr)++; printf("%s\n",ptr); ptr++; printf("%s\n",ptr); } Find the Outputs? CitiGroup7
Tell us the difference between these two : #include"stdio.h" #include<stdio.h> define in detial.  4
print ur name without using any semicolon in c/c++....  6
what is array?  6
related to rdbms query .  1
consider the following C code main() { int i=3,x; while(i>0) { x=func(i); i--; } int func(int n) { static sum=0; sum=sum+n; return(sum); } the final value of x is TCS3
How to swap two values using a single variable ? condition: Not to use Array and Pointer ?  4
what is the output of the following program? #include<stdio.h> void main() { int x=4,y=3,z; z=x-- -y; printf("\n%d %d %d",x,y,z); }  10
int zap(int n) { if(n<=1)then zap=1; else zap=zap(n-3)+zap(n-1); } then the call zap(6) gives the values of zap [a] 8 [b] 9 [c] 6 [d] 12 [e] 15 Wipro8
difference between memcpy and strcpy  1
how to find the binary of a number? Infosys5
how memory store byte Huawei3
What is the memory allocated by the following definition ? int (*x)(); ADITI2
44.what is the difference between strcpy() and memcpy() function? 45.what is output of the following statetment? 46.Printf(“%x”, -1<<4); ? 47.will the program compile? int i; scanf(“%d”,i); printf(“%d”,i); 48.write a string copy function routine? 49.swap two integer variables without using a third temporary variable? 50.how do you redirect stdout value from a program to a file? 51.write a program that finds the factorial of a number using recursion?  3
 
For more C Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com