C Programming Questions and Answers on Conditional Inclusion for Freshers

1. What is the output of this C code?

  1.     #include 
  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("WORLD\n");
  11.         #endif
  12.     }
a) HELLO
b) WORLD
c) HELLO WORLD
d) No Output
Answer: b
2. Comment on the following code?

  1.     #include 
  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: d
3. The “else if” in conditional inclusion is written by?

a) #else if
b) #elseif
c) #elsif
d) #elif
Answer: d
4. What is the output of this C code?
  1.     #include 
  2.     #define COLD
  3.     int main()
  4.     {
  5.         #ifdef COLD
  6.         printf("COLD\t");
  7.         #undef COLD
  8.         #endif
  9.         #ifdef COLD
  10.         printf("HOT\t");
  11.         #endif
  12.     }
a) HOT
b) COLD
c) COLD HOT
d) No Output
Answer: b
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: c
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: a
.
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: d
8. The #elif directive cannot appear after the preprocessor #else directive.

a) True
b) False
c) None of the mentioned
d) Varies
Answer: a
9 For each #if, #ifdef, and #ifndef directive.

a) There are zero or more #elif directives
b) Zero or one #else directive
c) One matching #endif directive
d) All of the mentioned
Answer: d
10. The #else directive is used for

a) Conditionally include source text if the previous #if, #ifdef, #ifndef, or #elif test fails.
b) Conditionally include source text if a macro name is not defined
c) Conditionally include source text if a macro name is defined
d) Ending conditional text
Answer: a
11. What is the output of this C code?

  1.     #include 
  2.     #define MIN 0
  3.     #if MIN
  4.     #define MAX 10
  5.     #endif
  6.     int main()
  7.     {
  8.         printf("%d %d\n", MAX, MIN);
  9.         return 0;
  10.     }
a) 10 0
b) Compile time error
c) Undefined behaviour
d) None of the mentioned
Answer: b
12. What is the output of this C code?

  1.     #include 
  2.     #define MIN 0
  3.     #ifdef MIN
  4.     #define MAX 10
  5.     #endif
  6.     int main()
  7.     {
  8.         printf("%d %d\n", MAX, MIN);
  9.         return 0;
  10.     }
a) 10 0
b) Compile time error
c) Undefined behaviour
d) None of the mentioned
Answer: a
13. What is the output of this C code?

  1.     #include 
  2.     #define MIN 0
  3.     #if defined(MIN) + defined(MAX)
  4.     #define MAX 10
  5.     #endif
  6.     int main()
  7.     {
  8.         printf("%d %d\n", MAX, MIN);
  9.         return 0;
  10.     }
a) 10 0
b) Compile time error
c) Undefined behaviour
d) Somegarbagevalue 0
Answer: a
14. What is the output of this C code?

  1.     #include 
  2.     #define MIN 0
  3.     #if defined(MIN) - (!defined(MAX))
  4.     #define MAX 10
  5.     #endif
  6.     int main()
  7.     {
  8.         printf("%d %d\n", MAX, MIN);
  9.         return 0;
  10.     }
a) 10 0
b) Compile time error
c) Undefined behaviour
d) Somegarbagevalue 0
Answer: b
15. What is the output of this C code?

  1.     #include 
  2.     #define MIN 0
  3.     #ifdef(MIN)
  4.     #define MAX 10
  5.     #endif
  6.     int main()
  7.     {
  8.         printf("%d %d\n", MAX, MIN);
  9.         return 0;
  10.     }
a) 10 0
b) Compile time error
c) Run time error
d) Preprocessor error
Answer: d
16. What is the output of code given below?

  1.     #include 
  2.     #define MIN 0);
  3.     #ifdef MIN
  4.     #define MAX 10
  5.     #endif
  6.     int main()
  7.     {
  8.         printf("%d %d\n", MAX, MIN
  9.         return 0;
  10.     }
a) 10 0
b) Compile time error due to illegal syntax for printf
c) Undefined behaviour
d) Compile time error due to illegal MIN value
Answer: a

Related

Java Multiple Choice Questions & Answers on Java.util package Maps for Freshers

1. Which of these object stores association between keys and values? a) Hash tableb) Mapc) Arrayd) String Answer: b 2. Which of these classes provide implementation of map interface? a) ArrayLis...

C Programming Questions and Answers on Initialization of Pointer Arrays for Freshers

1. To declare a 3 dimension array using pointers, which of the following is the correct syntax: a) char *a[][];b) char **a[];c) char ***a;d) all of the mentioned Answer: a 2. Comment on the outpu...

Java Multiple Choice Questions & Answers on Java.util – LinkedList, HashSet & TreeSet Class for Freshers

1. Which of these standard collection classes implements a linked list data structure? a) AbstractListb) LinkedListc) HashSetd) AbstractSet Answer: b 2. Which of these classes implements Set inte...

Post a Comment

emo-but-icon
:noprob:
:smile:
:shy:
:trope:
:sneered:
:happy:
:escort:
:rapt:
:love:
:heart:
:angry:
:hate:
:sad:
:sigh:
:disappointed:
:cry:
:fear:
:surprise:
:unbelieve:
:shit:
:like:
:dislike:
:clap:
:cuff:
:fist:
:ok:
:file:
:link:
:place:
:contact:

item