GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

  GeekInterview.com  >  Tech FAQs  >  OOPS

 Print  |  
Question:  could any one explan me what happens in this program.

main(){
int i=10;
i=(++i)/(i++);
printf("i=%d",i);
}




May 05, 2006 05:55:13 #4
 Malathi   Member Since: Visitor    Total Comments: N/A 

RE: could any one explan me what happens in this progr...
 

Here, ++i is previx expression -- i will be incrementd before the statement and i++ is postfix --> I will be incremented after the statement .

i=(++i)/(i++);  --- 1. ++i --> i will be incremented first.-> 11

                          2. 11/i ==11/10 = 1.1

                          3. (i++) = 1.1++ = 2.1

printf("i=%d",i);  --> %d id for integers, therefore 2.1 is trucated to 2.

Bye

     

 

Back To Question