Posted by Somesh Shinde
On
Tuesday, 28 June 2016
Difference between Post Increment (n++) and Pre Increment (++n)
Post Increment (n++): It increases the value of variable by 1 after execution of the statement.
Pre Increment (++n): It increases the value of variable by 1 before execution of the statement.
Program | Output |
class Demo
{
public static void main(String args[])
{
int n=10;
System.out.println(n);
System.out.println(n++);
System.out.println(n);
}
}
|
10
10
11
|
Program | Output |
class Demo
{
public static void main(String args[])
{
int n=10;
System.out.println(n);
System.out.println(++n);
System.out.println(n);
}
}
|
10
11
11
|
|
|
0 comments:
Post a Comment