Frequently asked technical Operator questions of placement in c programming language
1.What will be output of the following program?
Turbo C++ 3.0: c
Rule :- ++ is pre increment operator so in any arithmetic expression it first increment the value of variable by one in whole expression then starts assigning the final value of variable in the expression.
www.cinterviews.com appreciates your contribution please mail us the questions you have to cinterviews.blogspot.com@gmail.com so that it will be useful to our job search community
1.What will be output of the following program?
#include<stdio.h>
int main(){
float a=0.7;d
if(a<0.7){
printf("C");
}
else{
printf("C++");
}
return 0;
return 0;
}
Answer:
Turbo C++ 3.0: c
Turbo C ++4.5: c
Linux GCC: c
Visual C++: c
Explanation: 0.7 is double constant (Default). Its binary value is written in 64 bit.
Binary value of 0.7 = (0.1011 0011 0011 0011 0011 0011 0011 0011 0011 0011 0011 )
Now here variable a is a floating point variable while 0.7 is double constant. So variable a will contain only 32 bit value i.e.
a = 0.1011 0011 0011 0011 0011 0011 0011 0011 while
0.7 = 0.1011 0011 0011 0011 0011 0011 0011 0011 0011 0011 0011....
It is obvious a < 0.7
2.What will be output of the following program?
#include<stdio.h>
int main(){
int a=2,b=7,c=10;
c=a==b;
printf("%d",c);
return 0;
}
Answer:
Output:
Explanation:
== is relational operator which returns only two values.
Turbo C++ 3.0: 0
Turbo C ++4.5: 0
Linux GCC: 0
Visual C++: 0
== is relational operator which returns only two values.
0: If a == b is false
1: If a == b is true
Since
a=2
b=7
So, a == b is false hence b=0
3.What will be output of the following program?
Answer:
#include<stdio.h>
int main(){
int i=5,j;
j=++i+++i+++i;
printf("%d %d",i,j);
return 0;
}
Output:
Explanation:
Turbo C++ 3.0: 8 24
Turbo C ++4.5: Compilation error
Linux GCC: Compilation error
Visual C++: Compilation error
Rule :- ++ is pre increment operator so in any arithmetic expression it first increment the value of variable by one in whole expression then starts assigning the final value of variable in the expression.
Compiler will treat this expression j = ++i+++i+++i; as
i = ++i + ++i + ++i;
Initial value of i = 5 due to three pre increment operator final value of i=8.
Now final value of i i.e. 8
So, j=8+8+8
j=24 and
i=8
www.cinterviews.com appreciates your contribution please mail us the questions you have to cinterviews.blogspot.com@gmail.com so that it will be useful to our job search community
No comments:
Post a Comment