C MCQ set number 00697

1. What is the output of this C code?

  1.     #include <stdio.h>
  2.     #define SYSTEM 20
  3.     int main()
  4.     {
  5.         int a = 20;
  6.         #if SYSTEM == a
  7.         printf("HELLO ");
  8.         #endif
  9.         #if SYSTEM == 20
  10.         printf("WORLDn");
  11.         #endif
  12.     }

a) HELLO
b) WORLD
c) HELLO WORLD
d) No Output

Answer

Answer: b [Reason:] None.

2. Comment on the following code?

  1.     #include <stdio.h>
  2.     #define Cprog
  3.     int main()
  4.     {
  5.         int a = 2;
  6.         #ifdef Cprog
  7.         a = 1;
  8.         printf("%d", Cprog);
  9.     }

a) No output on execution
b) Output as 1
c) Output as 2
d) Compile time error

Answer

Answer: d [Reason:] None.

3. The “else if” in conditional inclusion is written by?
a) #else if
b) #elseif
c) #elsif
d) #elif

Answer

Answer: d [Reason:] None.

4. What is the output of this C code?

  1.     #include <stdio.h>
  2.     #define COLD
  3.     int main()
  4.     {
  5.         #ifdef COLD
  6.         printf("COLDt");
  7.         #undef COLD
  8.         #endif
  9.         #ifdef COLD
  10.         printf("HOTt");
  11.         #endif
  12.     }

a) HOT
b) COLD
c) COLD HOT
d) No Output

Answer

Answer: b [Reason:] None.

5. Which of the following sequences are unaccepted in C language?
a) #if
    #else
    #endif
b) #if
    #elif
    #endif
c) #if
    #if
    #endif
d) #if
    #undef
    #endif

Answer

Answer: c [Reason:] None.

6. In a conditional inclusion, if the condition that comes after the if holds.
a) Then the code up to the following #else or #elif or #endif is compiled
b) Then the code up to the following #endif is compiled even if #else or #elif is present
c) Then the code up to the following #eliif is compiled
d) None of the mentioned

Answer

Answer: a [Reason:] None.

7. Conditional inclusion can be used for
a) Preventing multiple declarations of a variable
b) Check for existence of a variable and doing something if it exists
c) Preventing multiple declarations of same function
d) All of the mentioned

Answer

Answer: d [Reason:] None.

8. The #elif directive cannot appear after the preprocessor #else directive.
a) True
b) False
c) None of the mentioned
d) Varies

Answer

Answer: a [Reason:] None.

ed010d383e1f191bdb025d5985cc03fc?s=120&d=mm&r=g

DistPub Team

Distance Publisher (DistPub.com) provide project writing help from year 2007 and provide writing and editing help to hundreds student every year.