Exforsys

Online Training

Result of Program

This is a discussion on Result of Program within the C and C++ forums, part of the Programming Talk category; I have idea about prefix and postfix operators and operations using these operators in C programming language. But I am ...


Go Back   Exforsys > Programming Talk > C and C++

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-05-2007, 06:35 PM
Senior Member
 
Join Date: Apr 2006
Posts: 125
ashlee is on a distinguished road
Thumbs up Result of Program

I have idea about prefix and postfix operators and operations using these operators in C programming language. But I am confused about the following program?
main()
{
int a=5,b=0;
y=a+++a+++a;
printf(" a=%d b=%d ",a,b);
}

How will the above get solved? I am confused on the operations. Kindly someone help me out.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 05-10-2007, 09:22 AM
Senior Member
 
Join Date: Apr 2006
Posts: 141
Adrian is on a distinguished road
The precedence of operators is first Postfix increment/decrement operator and the associativity for this is from left-to-right.
So we have a++ gets evaluated first and so the expression first becomes
y=a+++a+++a;
y=5+5+5=15
and then a gets increment twice and so a becomes 7

So your output would be
a=7 b=15;

But a small typo error you have made is instead of b=a+++a+++a; You have given as y=a+++a+++a;
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools

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
comp.lang.c Answers (Abridged) to Frequently Asked Questions (FAQ) Steve Summit Tech FAQ 0 06-15-2004 07:00 AM
comp.lang.c Answers (Abridged) to Frequently Asked Questions (FAQ) Steve Summit Tech FAQ 0 06-01-2004 07:01 AM
comp.lang.c Answers to Frequently Asked Questions (FAQ List) Steve Summit Tech FAQ 0 06-01-2004 07:00 AM
comp.lang.c Answers (Abridged) to Frequently Asked Questions (FAQ) Steve Summit Tech FAQ 0 05-15-2004 07:00 AM
Apple II Csa2 FAQs: Telecom Hardware & Transfers, Part 20/25 rubywand@swbell.net Tech FAQ 0 04-04-2004 08:29 AM


All times are GMT -4. The time now is 05:00 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0
Copyright 2004 - 2007 Exforsys Inc. All rights reserved.