Current location: Hot Scripts Forums » HotScripts.com Discussion » Hot Scripts Forum Questions, Suggestions and Feedback » Prefix & Postfix Increment in C++ question


Prefix & Postfix Increment in C++ question

Reply
  #1 (permalink)  
Old 12-16-11, 02:50 AM
sameerge sameerge is offline
New Member
 
Join Date: Dec 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Rolleyes Prefix & Postfix Increment in C++ question

Hi dears
I have trouble in this below question I want to know how that answer come:

#include<iostream.h>
#include<conio.h>
void main()
{
int x=20,y=35;
clrscr();
x=y++ + x++;
y=++y + ++x;
cout<<x<<y;
getch();
}

when I run this program I get this answer = 5794.

I can't understand how it come, when I solve one Individual line [ x=y++ + x++; ] like this

#include<iostream.h>
#include<conio.h>
void main()
{
int x=20,y=35;
clrscr();
x=y++ + x++;
cout<<x;
getch();
}

I get answer = 56 and when I solved this Individual Line [ y=++y + ++x; ] like this

#include<iostream.h>
#include<conio.h>
void main()
{
int x=20,y=35;
clrscr();
y=++y + ++x;
cout<<y;
getch();
}

I get answer =57 I know the basic principle of prefix & postfix increment in c++ and in my solution the answer should come 5657 instead of 5794 when we solve this full program

#include<iostream.h>
#include<conio.h>
void main()
{
int x=20,y=35;
clrscr();
x=y++ + x++;
y=++y + ++x;
cout<<x<<y;
getch();
}

Please explain how & why the answer comes 5794?
Reply With Quote
  #2 (permalink)  
Old 12-16-11, 06:34 AM
sameerge sameerge is offline
New Member
 
Join Date: Dec 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
answer

I got this thread answer by myself.......................thanks for reading the question.....
Reply With Quote
Reply

Bookmarks

Tags
c++, increment, postfix, prefix


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
C++ Tip : What is difference between Postfix and Prefix Operators? Learnbyexamples C/C++ 3 11-09-11 03:10 AM
Injecting a string into an If Statement ? nova912 PHP 4 07-21-06 02:04 PM
[PHP] Array question UmiSal Script Requests 1 04-05-04 01:52 PM
question and answer software jaydifox C/C++ 0 02-21-04 09:26 AM


All times are GMT -5. The time now is 09:59 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.