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?
a) a.out
b) sam
c) sam.out
d) None of the mentioned
View Answer

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

2. 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;
}

a) 8 4 2
b) 8 4 2
c) 8 4 4
d) 8 4 3
View Answer

Answer: c
Explanation: GCC compilers (32 bit compilers) size of:
double is 8 byte
long int is 8 byte
Character constant is 2 byte.
advertisement
advertisement

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

Note: Join free Sanfoundry classes at Telegram or Youtube
#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;
}

a) 0 0
b) 65536 -10
c) 0 65536
d) Compilation error
View Answer

Answer: a
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.
advertisement

4. 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;
}

a) 0
b) 10
c) Garbage Value
d) Any Memory address
View Answer

Answer: b
Explanation: In the following declaration
const int *p;
p can keep address of constant integer.
advertisement

5. 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;
}

a) 10
b) 9
c) 8
d) Error
View Answer

Answer: c
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.

6. Which of the following is integral data type?
a) void
b) char
c) float
d) double
View Answer

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<stdio.h>
int main()
{
    volatile int a=11;
    printf("%d",a);
    return 0;
}

a) 11
b) Garbage
c) -2
d) Cannot Predict
View Answer

Answer: d
Explanation: 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<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; 
}

a) -4
b) -5
c) 10
d) 11
View Answer

Answer: a
Explanation: Default value X is zero and
Z = Y + 1 = 5 + 1 = 6
So, a + b – p
=0 + 6 -10 = -4.

Sanfoundry Global Education & Learning Series – Compilers.

To practice all areas of Compilers, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.