© 2014 Firstsoft Technologies (P) Limited. login
Hi 'Guest'
Home SiteMap Contact Us Disclaimer
enggedu

C and C++ Interview Questions

19. Why Preincrement operator is faster than Postincrement Operator?

Ans:

The pre inc operator increments the value of that particular variable on that line itself the post inc operator increments the value of that particular variable after going on the next line
in simple words
eg.
e 5; on this line value of e 5
e++; on this line value of e 5
++e; on this line value of e 7.
gaurav mody.

Ex - 1: What will be printed as the result of the operation below:
main()
{
int x=5;
printf(“%d,%d,%dn”,x,x< <2,x>>2);
}
Ans: 5,20,1

Ex - 2: What will be printed as the result of the operation below?
#define swap(a,b) a=a+b;b=a-b;a=a-b;
void main()
{
int x=5, y=10;
swap (x,y);
printf(“%d %dn”,x,y);
swap2(x,y);
printf(“%d %dn”,x,y);
}
int swap2(int a, int b)
{
int temp;
temp=a;
b=a;
a=temp;
return 0;
}
Ans: 10, 5
10, 5

Ex - 3: What will be printed as the result of the operation below?
int x;
int modifyvalue()
{
return(x+=10);
}
int changevalue(int x)
{
return(x+=1);
}
void main()
{
int x=10;
x++;
changevalue(x);
x++;
modifyvalue();
printf("First output:%dn",x);
x++;
changevalue(x);
printf("Second output:%dn",x);
modifyvalue();
printf("Third output:%dn",x);
}
Ans: 12 , 13 , 13


SLogix Student Projects
bottom