Professional Documents
Culture Documents
http://www.word-to-pdf.abdio.com/
(
Word
to
PDF Unreg
istered ) http://www.word-to-pdf.abdio.com/
Skip to main content
Home
Search form
Search
Home
C Programming
C++ Programming
Python
Recent Articles
Follow Us
Programiz.com Facebook Page
Programiz.com Twitter Page
Programiz.com Google+ Page
Difference in Increment ++ Operator as Prefix and Postfix
In any programming (Java, C Programming, PHP etc. ), increment ++ and decrement -- operator are used for
increasing and decreasing the value of operand by 1 respectively.
Suppose, a=5 then,
++a;
//a becomes
a++;
//a becomes
--a;
//a becomes
a--;
//a becomes
6
7
6
5
Simple enough till now but, there is a slight but very important difference that a programmer should remember while
using these operators.
istered ) http://www.word-to-pdf.abdio.com/
Languages
C Programming
C++ Programming
PHP
Java
C Programming Example
#include <stdio.h>
int main(){
int var=5;
printf("%d\n",var++);
/* 5 is displayed then, only var is increased to 6 */
printf("%d",++var);
/* Initially, var=6 then, it is increased to 7 then, only displayed */
return 0;
}
PHP Example
<?php
Svar=5;
echo $var++."<br/>";
echo ++$var;
?>
Java Example
class Operator {
public static void main(String[] args){
int var=5;
System.out.println(var++);
System.out.println("\n"+ ++var);
}
(
Word
to
PDF Unreg
(
Word
to
PDF Unreg
istered ) http://www.word-to-pdf.abdio.com/
}
Comment Text
Web page addresses and e-mail addresses turn into links automatically.
Lines and paragraphs break automatically.
Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
Code snippets in <code>...</code> or <source>...</source> automatically will be pretty printed.
Word verification * Type the characters you see in this picture. (verify using audio) Type the characters you see in the
picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.