Difference between x++ and ++x;
Difference between x-- and --x;
19 139343 Banfa 9,065
Recognized Expert Moderator Expert
++x is pre-increment and x++ is post-increment that is in the first x is incremented before being used and in the second x is incremented after being used.
This is most easily demonstrated with a small program - #include <stdlib.h>
-
#include <stdio.h>
-
-
int main(int argc, char **argp)
-
{
-
int x = 5;
-
-
printf("x=%d\n", ++x);
-
printf("x=%d\n", x++);
-
printf("x=%d\n", x);
-
-
return EXIT_SUCCESS;
-
}
The output of this program is
In the first printf statement x is incremented before being passed to printf so the value 6 is output, in the second x is passed to printf (so 6 is output) and then incremented and the 3rd printf statement just shows that post increment following the previous statement by outputting x again which now has the value 7.
Difference between x-- and --x;
Banfa 9,065
Recognized Expert Moderator Expert
I would have thought you could have modified the program I posted to find out, where ++ is increment -- is decrement, apart from that that act in a similar manor.
Thanks!!!!!
an other method
m+=1; is post increment
or m-=1 is post decrement
JosAH 11,448
Recognized Expert MVP an other method
m+=1; is post increment
or m-=1 is post decrement
Have you tried it? The value of the expression "m+=1" equals "m+1" so it is
more like a pre increment.
kind regards,
Jos
yes i tried practicaly " m+1" is eqal to "m+=1" "++m" is pre increment
if you have any other idea please reply
i'll wait 4 ur +ive response
Regardz Maan.... JosAH 11,448
Recognized Expert MVP
yes i tried practicaly " m+1" is eqal to "m+=1" "++m" is pre increment
Erm, yes that's what I wrote; you wrote that m+= 1 had the same value as
the *post* increment expression (see above).
kind regards,
Jos
thank u buddy...i had the same question and ur answer really worked out:)
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Rittersporn |
last post by:
My humble attempt to model pre/postconditions with
decorators :-) It's also my first experiment
with decorators.
If you have any ideas or thoughts on how to
improve the code snippet, I'll be happy to
learn more.
Enjoy :-)
def condition(pretext,posttext=""):
|
by: yensao |
last post by:
Hi,
I have a hard time to understand difference and similarities between
Relational database model and the Object-Oriented model. Can somebody
help me with this?
Thank you in advance.
Yensao
|
by: Emil Dotchevski |
last post by:
I have a table that is at 100% width, which contains a <TD> that is
80% of that. In the <TD> I want to put pre-formatted text (the output
from a C++ compiler, to be more precise) and I'd like the text to use
scroll bars if it does not fit.
I can't get this to work, no matter what combination of <PRE>, width,
and style I try. Any help greatly appreciated.
Thanks,
Emil
|
by: Headless |
last post by:
I've marked up song lyrics with the <pre> tag because it seems the most
appropriate type of markup for the type of data. This results in
inefficient use of horizontal space due to UA's default rendering of
<pre> in a fixed width font.
To change that I'd have to specify a proportional font family, thereby
falling into the size pitfall that is associated with any sort of author
specified font family:
a) If I specify a sans serif font...
|
by: Neal |
last post by:
A few questions about pre...
When presenting preformatted text using the white-space: pre;
property/value, Opera renders long lines at small viewport widths as
exiting the borders of the element, IE6 extends the element to contain the
line. Both necessitate horizontal scrolling.
1) Is one considered incorrect, or are both fair interpretations of the
recommendation?
| |
by: WittyGuy |
last post by:
Hi,
What is the major difference between function overloading and function
templates?
Thanks!
http://www.gotw.ca/resources/clcm.htm for info about ]
|
by: August Karlstrom |
last post by:
Hello all,
If c is a char then is there any difference between
c = '\0'
and
c = 0
|
by: Eric Lindsay |
last post by:
I can't figure how to best display little snippets of shell script using
<pre>. I just got around to organising to bulk validate some of my web
pages, and one of the problems occurs with Bash shell pieces like this:
<pre><code>
#!/bin/sh
ftp -i -n ftp.server.com< <EOF
user username password
epsv4
cd /
|
by: Sathyaish |
last post by:
Can we have a pre-processor directive such as
#define LEN 132
in C# v1.1? If so, are there any restrictions as to the scope of such a
declaration?
|
by: San |
last post by:
hi there,
I am new to c++ and tryig to learn the basics of the c++ concepts.
While I was reading the templates, I realize that the templates are a
syntax that the compilar expands pased upon the type specified. This is
much similar like a macro expansion in C.
can anyone please explain advantages of one over the other ?
Thanks in advance -
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |