Answer the Question

0
1. a=5,what is the output of a++ and ++a?
2. i=3;
     j=2*(i++);
     k=2*(++i);
      what is the output of j and k?
By : nandigam anjali    On : 28-Dec-2012     Answers : 5      Report Abuse
Your Answer
Previous Answers
0
1.for a++ gives a=5; and ++a gives a=6;
2.
On : 22-Jan-2013   Accept Count : 0  
0
stepwise answer is here:

(1)here       a=5,                       (1)      a=5,
(2)and        a++=5,                   (2)++a=6
(3)and now a=6                        (3)      a=6

so answer is:

a++=5 and ++a=6
a++ is post operator, i.e. it's effect will be after one line and ++a is pre operator, i.e. it increases it's value first than performs other operations......

here is a great example for you ::::




    #include<iostream.h>
    #include<conio.h>
    void main()
    {
    clrscr();
    int a,b;
    a=1;
    cout<<a<<endl;
    cout<<a++<<endl;
    cout<<a<<endl<<endl;
    b=5;
    cout<<b<<endl;
    cout<<++b<<endl;
    cout<<b<<endl;
    getch();
    }



o/p:::::
1
1
2
5
6
6
On : 22-Jan-2013   Accept Count : 0  
0
1.a++=6,++a=6
2.j=8,k=8
On : 19-Jan-2013   Accept Count : 0  
By : CHITRA
0
1)a++=5, ++a=6
2)j=6,k=12
On : 10-Jan-2013   Accept Count : 0  
0
j=6 k=10
On : 29-Dec-2012   Accept Count : 0  
By : Anil kumar