Compilers Multiple Choice Questions on “Cross Compiler”.
1. If we compile the sam.c file with the command “gcc -o sam sam.c”, then the executable file will be?
a) a.out
b) sam
c) sam.out
d) None of the mentioned
Answer: b
Clarification: This is how the GCC is designed to take names of executable files.
2. What will be output of the following code?
#include int main() { printf("%dt",sizeof(6.5)); printf("%dt",sizeof(90000)); printf("%d",sizeof('A')); return 0; }
a) 8 4 2
b) 8 4 2
c) 8 4 4
d) 8 4 3
Answer: c
Clarification: GCC compilers (32 bit compilers) size of:
double is 8 byte
long int is 8 byte
Character constant is 2 byte.
3. What will be output of the following c code? ( according to GCC compiler)
#include int main() { signed x; unsigned y; x = 10 +- 10u + 10u +- 10; y = x; if(x==y) printf("%d %d",x,y); else if(x!=y) printf("%u %u",x,y); return 0; }
a) 0 0
b) 65536 -10
c) 0 65536
d) Compilation error
Answer: a
Clarification: Consider on the expression:
x = 10 +- 10u + 10u +- 10;
10: It is signed integer constant.
10u: It is unsigned integer constant.
X: It is signed integer variable.
As we know operators enjoy higher precedence than binary operators. So
x = 10 + (-10u) + 10u + (-10);
= 10 + -10 + 10 + (-10);
= 0
So, Corresponding signed value of unsigned 10u is +10.
4. What will be output of the following c code?
#include int main() { const int *p; int a=10; p=&a; printf("%d",*p); return 0; }
a) 0
b) 10
c) Garbage Value
d) Any Memory address
Answer: b
Clarification: In the following declaration
const int *p;
p can keep address of constant integer.
5. What will be output of the following c code?
#include int main() { int a= sizeof(signed) +sizeof(unsigned); int b=sizeof(const)+sizeof(volatile); printf("%d",a+++b); return 0; }
a) 10
b) 9
c) 8
d) Error
Answer: c
Clarification: Default data type of signed, unsigned, const and volatile is intSo, a = 4 and b =4
Now, a+++b
= a++ + b
= 4 + 4 //due to post increment operator.
=8
But in Linux gcc compiler size of int is 4 byte so your out will be 16.
6. Which of the following is integral data type?
a) void
b) char
c) float
d) double
Answer: b
Expanation: In c char is integral data type. It stores the ASCII value.
7. What will be output of the following c code?
#include int main() { volatile int a=11; printf("%d",a); return 0; }
a) 11
b) Garbage
c) -2
d) Cannot Predict
Answer: d
Clarification: Value of volatile variable can’t be predicted because its value can be changed by any microprocessor interrupt.
8. What will be output of the following c code?
#include const enum Alpha { X, Y=5, Z }p=10; int main() { enum Alpha a,b; a= X; b= Z; printf("%d",a+b-p); return 0; }
a) -4
b) -5
c) 10
d) 11
Answer: a
Clarification: Default value X is zero and
Z = Y + 1 = 5 + 1 = 6
So, a + b – p
=0 + 6 -10 = -4.