Forum     

Go Back   Digit Technology Discussion Forum > Portables, Peripherals and Electronics > QnA (read only)
Register FAQ Calendar Mark Forums Read

QnA (read only) Mods please help transfer the contents of this forum to proper sections. :)


 
 
LinkBack Thread Tools Search this Thread Display Modes
Old 12-08-2007, 09:11 PM   #1 (permalink)
Hey here is the aks
 
arunks's Avatar
 
Join Date: Jan 2006
Location: punjab
Posts: 805
Default help me urgently to understand this in C


int a=10,s;

s= ++a + a++ + --a + a--;


what would be the poutput for s??


according to me it should be 44 but when i run this code in C it displays 40...

why is it so... plz anybdy help me to understand that?

but if i use this

int a=10,s;
printf("%d",++a + a++ + --a + a--);

this code displays 44 as expected by me..

But according to me no difference should be there in above two codes..

Plz reply fast as i need this answer urgently
__________________
yours truly
arun
The aks!!

have a nice day
arunks is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 13-08-2007, 01:39 PM   #2 (permalink)
The Frozen Nova
 
casanova's Avatar
 
Join Date: Sep 2004
Location: Trespasser in Virtual Land
Posts: 1,641
Default Re: help me urgently to understand this in C

++a = preincrement i.e; increment then assign
so if, b=++a then b=11, a=11
a++ =postincrement i.e; assign then increment
so if, b=a++ then b=10, a=11

s=++a + a++ + --a +a-- ;
this statement is executed as follows
s= ++a + a++ + --a + a--
s= 11 + 10 + 9 + 10 //increment operators are substituted first
s= 40

printf (%d",++a + a++ + --a + a--)
this statement is executed in left to right precedence
therefore ans=44
__________________
I dream of a better tomorrow... where chickens can cross roads and not have their motives questioned.

www.nerdweed.blogspot.com
casanova is offline  
Old 13-08-2007, 02:48 PM   #3 (permalink)
Wise Old Owl
 
piyush gupta's Avatar
 
Join Date: Sep 2005
Location: never land
Posts: 1,284
Default Re: help me urgently to understand this in C

in first case it will be implemented from reverrse order

i thinks cassanova already explained u in details
more here

http://en.allexperts.com/q/C-1040/In...-operators.htm
piyush gupta is offline  
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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


Similar Threads
Thread Thread Starter Forum Replies Last Post
When will people understand...................... abrakadabra Open Source 61 10-08-2007 02:18 PM
New to Linux. Want to understand the basics bhushan05d251 Open Source 2 08-05-2007 01:18 PM
I dont understand. shashank_digitreader Gamerz 12 28-01-2007 01:01 AM
I CAN'T EVEN UNDERSTAND THE PROBLEM... wizard_with_a_wand QnA (read only) 6 06-12-2004 05:07 AM

 
Latest Threads
- by Tenida
- by Charan
- by abhidev

Advertisement




All times are GMT +5.5. The time now is 10:22 AM.


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

Search Engine Optimization by vBSEO 3.3.2