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);
}




June 06, 2006 07:51:54 #7
 swapna s   Member Since: Visitor    Total Comments: N/A 

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

Solution:-

      i = 10;

      i = (++i)/(i++)

      ++i is preincrement the value of i before executing the statement. 

      i++ is post increment the value of i after executing the statement     

Here ++i = 11

      i = (++i) / (i++);  // 11/11 = 1 

           After executing the above statement post increment operator (ie i++)

           is excuted. Becaz of that i's value is incremented to 2. 

      

     

 

Back To Question