Forum     

Go Back   Digit Technology Discussion Forum > Software > Programming
Register FAQ Calendar Mark Forums Read

Programming The destination for developers - C, C++, Java, Python and the lot


Closed Thread
 
LinkBack Thread Tools Display Modes
Old 06-11-2008, 07:24 PM   #1 (permalink)
Apprentice
 
dare_devil's Avatar
 
Join Date: Aug 2007
Location: patiala
Posts: 68
Exclamation help with c/c++



please help me finding correct explanation for following problems


1:) int i=5;
printf("%d", i++ *++i);

2:)int i=5,j=6;
printf("%d",i+++j);

3:) what's difference between these two outputs, i mean why out put different
j=5;
i=j++ * ++j;
and
j=j++ *++j;


please help me
__________________
Dell Studio 15, 2.1 Gh, 4 Gb Ram, 500 Gb hd, 512 mb ati 4570, creative sound blaster windows vista sp2
dare_devil is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 06-11-2008, 07:37 PM   #2 (permalink)
हॉर्न ओके प्लीज़
 
victor_rambo's Avatar
 
Join Date: Sep 2007
Posts: 1,493
Default Re: help with c/c++

I am a PHP guy, but let me see if the same explanation is valid for C too!

a++ means a is returned before incrementing
++a means a is first incremented and then returned!

again, I am a PHP guy, so this may be wrong!
__________________
विक्टर रॅंबो - चाणकया प्रभावित व्यक्ति

गीक होना माँगता
victor_rambo is offline  
Old 06-11-2008, 07:41 PM   #3 (permalink)
Apprentice
 
dare_devil's Avatar
 
Join Date: Aug 2007
Location: patiala
Posts: 68
Default Re: help with c/c++

thanks, but i know priorities, but i am unable to understand behavior of these in an expression and functions
__________________
Dell Studio 15, 2.1 Gh, 4 Gb Ram, 500 Gb hd, 512 mb ati 4570, creative sound blaster windows vista sp2
dare_devil is offline  
Old 06-11-2008, 10:14 PM   #4 (permalink)
Right Off the Assembly Line
 
Join Date: Nov 2008
Location: Bangalore
Posts: 6
Default Re: help with c/c++

Except for the second one, both 1 and 3 that you've given have undefined behavior. What this means that you cannot predict what the output would be and may vary on different compilers.

This is because the same variable is being modified twice between 2 sequence points. For more details, search the net for "C sequence points"

Hope this helps
Srinivasa S
srinivasa.s is offline  
Closed Thread

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


 
Latest Threads
- by gforz
- by soumya
- by Sujeet
- by icebags
- by Charan

Advertisement




All times are GMT +5.5. The time now is 02:58 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2