TechTalkz.com Logo Ask the Expert

Go Back   TechTalkz.com Technology & Computer Troubleshooting Forums > TechTalkz Member Reviews & Guides > Guides

Notices

C++ Guide: Part 2

Guides


Comment
 
Article Tools Display Modes
<!-- google_ad_section_start -->C++ Guide: Part 2<!-- google_ad_section_end -->
C++ Guide: Part 2
Published by Dark Star
20-10-2006
Smile Increment Decrement Operators


INCREMENT OPERATOR

++ Increases the value by one. If it is used before or after the variable.....
Code:
i++ means i=i+1;
++i means i+1=i;

Both the formula are very diff and can the whole output, i=i+1 means that incrementation is done after the value is called. But i+1=i; means incrementation is done before the value is called.
For e.g. :-
Code:
int i;
i=10;
i=i++;
cout<<i;
Here first the value is incremented then the value is printed and the output will come 11. But if the same program is written in a way like this:-
Code:
int i;
i=10;
cout<<i++;

Then the output will be 10 no incrementation will be done beacuse as I already told i++ means i=i+1
so the compiler will first print the value of i then it will increament.
Also the same program with diff result:--
Code:
int i;
i=10;
cout<<++i;

Here the output will be 11 incrementation will be done beacuse as I already told ++i means i+1=i
so the compiler will first increament the value then it will print the value of i.
Note:- The following topic is important if U have any problem then please ask...
For e.g: -
Code:
int i,j;
i=10;
j=i++;
cout<<i<<" "<<j;
Here the output will be 10 11 . Here the value of i is assigned to j then in the value of i there is post incrementation of 1 so the final value of i remains same and j is 11.
MULTIPlE INCREMENTS

SO after simple increment and decrement move into the second chamber of complicated increments this type of increment are rarely used in programs but they can be asked in the outputs so as a guider I have to tell everything .
These type of increments and decrements are used in same line and with same integar or diff integar..
For e.g. :-----
Code:
void main()
{
clrscr();
int x;
x=10;
cout<<x++<<" "<<++x;
getch();
}
In the above program there are 2 output in the same line and the integer is same so the output will go from left to right but the assigning of numbers will be from right to left..
As the initial value of x is 10 and for assigning heading from right the first thing is ++x means x+1=x
so the value become 11. Then there is x++ means x=x+1; so the comp will 1'st print the value then it will increment it so the value remains same as 11.
The final output is 11 11.
I am not going into deep of this because this is not too much important as far as I know. SO lets start the loop.

Published by
Dark Star's Avatar
Elite Member (1000+)
Join Date: May 2006
Location: /dev/had0
Age: 20
Posts: 1,627
Rep Power: 45
Dark Star is just GreatDark Star is just GreatDark Star is just GreatDark Star is just GreatDark Star is just GreatDark Star is just GreatDark Star is just GreatDark Star is just GreatDark Star is just GreatDark Star is just GreatDark Star is just Great

Contents

Article Tools

Latest 5 articles

Featured Articles
<<  <    Next Page: LOOPS /REPETITIONS/ITERATIONS (Page 2 of 6)    >  >>
Old 22-10-2006, 12:37 PM   #1
Senior Member (500+)
 
Join Date: Jun 2006
Location: Mumbai.
Age: 17
Posts: 505
Thanks: 6
Thanked 27 Times in 22 Posts
Rep Power: 18 Sam RuleZ has much to be proud ofSam RuleZ has much to be proud ofSam RuleZ has much to be proud ofSam RuleZ has much to be proud ofSam RuleZ has much to be proud ofSam RuleZ has much to be proud ofSam RuleZ has much to be proud ofSam RuleZ has much to be proud of
Send a message via Yahoo to Sam RuleZ
Nice guide !
__________________
"Its better to get burnt, than to fade away"-Kurt Cobain.

Sam RuleZ is offline   Reply With Quote
Old 22-10-2006, 01:45 PM   #2
ƒ(ψ)=ΘΊΧφ
 
bakuryu's Avatar
 
Join Date: May 2006
Location: India
Age: 24
Posts: 6,621
Thanks: 19
Thanked 649 Times in 605 Posts
Rep Power: 87 bakuryu has a brilliant futurebakuryu has a brilliant futurebakuryu has a brilliant futurebakuryu has a brilliant futurebakuryu has a brilliant futurebakuryu has a brilliant futurebakuryu has a brilliant futurebakuryu has a brilliant futurebakuryu has a brilliant futurebakuryu has a brilliant futurebakuryu has a brilliant future


OS: Windows XP Windows Vista Windows 7


Send a message via Yahoo to bakuryu
Quote:
i+1=i;
doesn't make any sense ..... and is logically incorrect.

a = i++;
// means :
// a = i;
// i = i + 1;

and a = ++i;
//means
// i = i + 1; (and not i+1 = i)
// a = i;


Quote:
  1. (1)The loop will not get executed if the given condition becomes false.
or if the expression is numerically 0. Any number other than 0 is considered TRUE, 0 is considered FALSE

Quote:
(1)The loop will be executed till the condition is false the result will be presented as soon as the condition becomes false.
Only if there's no break statement inside the loop. And the control comes out of the loop when the condition evaluates to FALSE, rather than "result will be presented as soon as the condition becomes false."
__________________
Please don't click here

Last edited by bakuryu; 22-10-2006 at 01:50 PM..
bakuryu is offline   Reply With Quote
Old 22-10-2006, 07:44 PM   #3
Junior Member (25+)
 
Join Date: Sep 2006
Age: 24
Posts: 64
Thanks: 7
Thanked 5 Times in 5 Posts
Rep Power: 3 luvrohit85 will become famous soon enough
hello

from where do u get this c++ guide book online can please tell me the website so that i can download it..
__________________
.RoHiTkUmAr.
luvrohit85 is offline   Reply With Quote
Old 22-10-2006, 09:56 PM   #4
Elite Member (1000+)
 
Dark Star's Avatar
 
Join Date: May 2006
Location: /dev/had0
Age: 20
Posts: 1,627
Thanks: 98
Thanked 172 Times in 146 Posts
Rep Power: 45 Dark Star is just GreatDark Star is just GreatDark Star is just GreatDark Star is just GreatDark Star is just GreatDark Star is just GreatDark Star is just GreatDark Star is just GreatDark Star is just GreatDark Star is just GreatDark Star is just Great


OS: Linux


Hey I had made it by my own beleive me
Dark Star is offline   Reply With Quote
Old 30-10-2006, 07:13 PM   #5
Founder
 
Strider's Avatar
 
Join Date: Nov 2005
Location: The Last City Zion!
Posts: 3,876
Thanks: 370
Thanked 410 Times in 355 Posts
Rep Power: 67 Strider is just GreatStrider is just GreatStrider is just GreatStrider is just GreatStrider is just GreatStrider is just GreatStrider is just GreatStrider is just GreatStrider is just GreatStrider is just GreatStrider is just Great


OS: Windows XP Windows Server 2003 / Windows Server 2008 Windows Vista Windows 7 Linux


Keep it up shah.. Good work.. Kepp them coming
Strider is offline   Reply With Quote
Comment

Article Tools
Display Modes


Similar Threads
Article Article Starter Category Comments Last Post
IE7 Cache, Part 2 BruceD Internet Explorer 2 28-08-2007 08:06 PM
IE7 Cache, Part 2 BruceD Internet Explorer 0 28-08-2007 07:57 PM
Re: I am Amazed - Part 33 1/3 MarkyMarc43 Windows Vista All 1 17-08-2007 07:34 PM
I am amazed part 2.... Tiberius Windows Vista All 9 17-08-2007 07:32 PM
Re: I am Amazed - Part 33 1/3 Homer Schwartz Windows Vista All 0 17-08-2007 07:21 PM


< Home - Windows Help - MS Office Help - Hardware Support >


New To Site? Need Help?

All times are GMT +5.5. The time now is 12:06 AM.


vBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO
Copyright © 2005-2010, TechTalkz.com. All Rights Reserved - Privacy Policy
Valid XHTML 1.0 Transitional