Thursday, March 5, 2009
Question number 01 (C/C++)
Code:
int a=10,b;
b=a++ + ++a;
printf("%d,%d,%d,%d",b,a++,a,++a);
what will be the output when following code is executed
Choice 1
12,10,11,13
Choice 2
22,10,11,13
Choice 3
22,11,11,11
Choice 4
12,11,11,11
Choice 5
22,13,13,13[Ans]
int a=10,b;
b=a++ + ++a;
printf("%d,%d,%d,%d",b,a++,a,++a);
what will be the output when following code is executed
Choice 1
12,10,11,13
Choice 2
22,10,11,13
Choice 3
22,11,11,11
Choice 4
12,11,11,11
Choice 5
22,13,13,13[Ans]
C/C++ tips Today
Suppose x, y two integer type variable
If we swapping value x to y and y to x general c/c++ code:
int x,y,temp;
temp=x;
x=y;
y=temp;
Now, optimized code is:
int x,y;
x=x+y;
y=x-y;
x=x-y;
So, we can swapping by using two variables instead of three variables
If we swapping value x to y and y to x general c/c++ code:
int x,y,temp;
temp=x;
x=y;
y=temp;
Now, optimized code is:
int x,y;
x=x+y;
y=x-y;
x=x-y;
So, we can swapping by using two variables instead of three variables
Subscribe to:
Posts (Atom)