6.
What will be output when you will execute following c code?
#include
enum A{
x,y=5,
enum B{
p=10,q
}varp;
}varx;
int main(){
printf("%d %d",x,varp.q);
return 0;
return 0;
}
Choose all that apply:
A. | 0 11 | |
B. | 5 10 | |
C. | 4 11 | |
D. | 0 10 | |
E. | Compilation error |
Answer. E
Explanation:
Turbo C++ 3.0: Compilation error
Turbo C ++4.5: Compilation error
Linux GCC: Compilation error
Visual C++: Compilation error
Nesting of enum constant is not possible in c.
-------------------------------------------------------------------
7.
What will be output when you will execute following c code?
#include
int main(){
char a=250;
int expr;
expr= a+ !a + ~a + ++a;
printf("%d",expr);
return 0;
return 0;
}
Choose all that apply:
A. | 249 | |
B. | 250 | |
C. | 0 | |
D. | -6 | |
E. | Compilation error |
Answer: D
Explanation:
Turbo C++ 3.0: -6
Turbo C ++4.5: -6
Linux GCC: -6
Visual C++: -6
char a = 250;
250 is beyond the range of signed char. Its corresponding cyclic value is: -6
So, a = -6
Consider on the expression:
expr= a+ !a + ~a + ++a;
Operator! , ~ and ++ have equal precedence. And it associative is right to left.
So, First ++ operator will perform the operation. So value a will -5
Now,
Expr = -5 + !-5 + ~-5 + -5
= -5 + !-5 + 4 - 5
= -5 + 0 + 4 -5
= -6
---------------------------------------------------
8.
What is the range of signed int data type in that compiler in which size of int is two byte?
A. -255 to 255
B. -32767 to 32767
C. -32768 to 32768
D. -32767 to 32768
E. -32768 to 32767
Answer: E
Explanation:
Size of int is always equal to word length of micro preprocessor in which your compiler has based.
----------------------------------------------------
9.
Which of the following is integral data type?
A. | void | |
B. | char | |
C. | float | |
D. | double | |
E. | None of these |
Answer: B
Explanation:
In c char is integral data type. It stores the ASCII value of any character constant.
-------------------------------------------------------------------
10.
What will be output when you will execute following c code?
#include
int main(){
signed x,a;
unsigned y,b;
a=(signed)10u;
b=(unsigned)-10;
y = (signed)10u + (unsigned)-10;
x = y;
printf("%d %u\t",a,b);
if(x==y)
printf("%d %d",x,y);
else if(x!=y)
printf("%u %u",x,y);
return 0;
return 0;
}
Choose all that apply:
A. | 10 -10 0 0 | |
B. | 10 -10 65516 -10 | |
C. | 10 -10 10 -10 | |
D. | 10 65526 0 0 | |
E. | Compilation error |
Answer: D
Explanation:
Turbo C++ 3.0: 10 65526 0 0
Turbo C ++4.5: 10 65526 0 0
Linux GCC: 10 4294967286 0 0
Visual C++: 10 4294967286 0 0
a=(signed)10u;
signed value of 10u is +10
so, a=10
b=(unsigned)-10;
unsigned value of -10 is :
MAX_VALUE_OF_UNSIGNED_INT – 10 + 1
In turbo c 3.0 complier max value of unsigned int is 65535
So, b = 65526
y = (signed)10u + (unsigned)-10;
= 10 + 65526 = 65536 = 0 (Since 65536 is beyond the range of unsigned int. zero is its corresponding cyclic vlaue)
X = y = 0
----------------------------------------------
----------------------------------------------
More Imp Topics: