i++ and ++i

Reply

Join Date: Aug 2007
Posts: 1
Reputation: balu116 is an unknown quantity at this point 
Solved Threads: 0
balu116 balu116 is offline Offline
Newbie Poster

Re: i++ and ++i

 
0
  #31
Oct 8th, 2007
void main()
{
int i=3;
printf("%d,%d,%d",i,i++,++i);
getch();
}
o/p:
5,4,4
if we r using ++i it will increment and it will asign to i so ans is 4
if we r using i++ it will increment but it assign to i so ans is 4
b'coz of i++ i value is 5.for clarifications execute the program
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,540
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 704
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: i++ and ++i

 
0
  #32
Oct 8th, 2007
Not only is your example horribly broken, it's not even a valid example of the point you're trying to make.

>void main()
Implementation-defined behavior. main is required to return int.

>printf("%d,%d,%d",i,i++,++i);
Undefined behavior. The commas in an argument list do not constitute sequence points, and ++ modifies its operand.
Undefined behavior. You didn't include stdio.h, and functions that take variable arguments require a prototype in scope.

>getch();
Implementation-defined behavior. You didn't include a header that declares getch, and getch isn't a standard function.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 111
Reputation: ChaseVoid is an unknown quantity at this point 
Solved Threads: 11
ChaseVoid's Avatar
ChaseVoid ChaseVoid is offline Offline
Junior Poster

Re: i++ and ++i

 
0
  #33
Oct 8th, 2007
Haahaa, good one Narue, But hell yeah that example will only give out errors.

Btw, balu116, please use the code tags. Posting source code like that is rude.
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,851
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: i++ and ++i

 
0
  #34
Oct 8th, 2007
When did this become the noob gets it wrong thread?

It seems a magnet for 1-post people to chip in with their "interpretation" only to be corrected for getting some aspect of "side effect" or "sequence point" wrong.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 111
Reputation: ChaseVoid is an unknown quantity at this point 
Solved Threads: 11
ChaseVoid's Avatar
ChaseVoid ChaseVoid is offline Offline
Junior Poster

Re: i++ and ++i

 
0
  #35
Oct 8th, 2007
xD but it can't be helped but corrected. Since others who are new here might get it wrong (which happens a lot). A good code writing practice is always appreciated.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC