Compilers Questions and Answers – Cross Compiler – 2

This set of Compilers Multiple Choice Questions & Answers (MCQs) focuses on “Cross Compiler – 2”.

1. If we compile the sam.c file with the command “gcc -o sam sam.c”, then the executable file will be
2. a) a.out
3. b) sam
4. c) sam.out
5. d) None of the mentioned

Explanation: This is how the GCC is designed to take names of executable files.

1. What will be output of the following code?

#include<stdio.h>

int main()

{

printf(“%d\t”,sizeof(6.5));

printf(“%d\t”,sizeof(90000));

printf(“%d”,sizeof(‘A’));

return 0;

}

1. a) 8 4 2
2. b) 8 4 2
3. c) 8 4 4
4. d) 8 4 3

Explanation: GCC compilers (32 bit compilers) size of:

double is 8 byte

long int is 8 byte

Character constant is 2 byte.

1. What will be output of the following c code? ( according to GCC compiler)

#include<stdio.h>

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;

}

1. a) 0 0
2. b) 65536 -10
3. c) 0 65536
4. d) Compilation error

Explanation: 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.

1. What will be output of the following c code?

#include<stdio.h>

int main()

{

const int *p;

int a=10;

p=&a;

printf(“%d”,*p);

return 0;

}

1. a) 0
2. b) 10
3. c) Garbage Value

Explanation: In the following declaration

const int *p;

p can keep address of constant integer.

1. What will be output of the following c code?

#include<stdio.h>

int main()

{

int a= sizeof(signed) +sizeof(unsigned);

int b=sizeof(const)+sizeof(volatile);

printf(“%d”,a+++b);

return 0;

}

1. a) 10
2. b) 9
3. c) 8
4. d) Error

Explanation: 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.

1. Which of the following is integral data type?
2. a) void
3. b) char
4. c) float
5. d) double

Expanation:

In c char is integral data type. It stores the ASCII value .

1. What will be output of the following c code?

#include<stdio.h>

int main()

{

volatile int a=11;

printf(“%d”,a);

return 0;

}

1. a) 11
2. b) Garbage
3. c) -2
4. d) Cannot Predict

Explanation: Value of volatile variable can’t be predicted because its value can be changed by any microprocessor interrupt.

1. What will be output of the following c code?

#include<stdio.h>

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;

}

1. a) -4
2. b) -5
3. c) 10
4. d) 11