Multiple Choice Questions and Answers for – Conditional Expressions in C Language

1. What is the output of this C code?
  1.     #include 
  2.     int main()
  3.     {
  4.         int x = 2, y = 0;
  5.         int z = (y++) ? y == 1 && x : 0;
  6.         printf("%d\n", z);
  7.         return 0;
  8.     }
a) 0
b) 1
c) Undefined behaviour
d) Compile time error
Answer:a
2. What is the output of this C code?
  1.     #include 
  2.     int main()
  3.     {
  4.         int x = 1;
  5.         int y =  x == 1 ? getchar(): 2;
  6.         printf("%d\n", y);
  7.     }
a) Compile time error
b) Whatever character getchar function returns
c) Ascii value of character getchar function returns
d) 2
Answer:c
3. What is the output of this C code?
  1.     #include 
  2.     int main()
  3.     {
  4.         int x = 1;
  5.         short int i = 2;
  6.         float f = 3;
  7.         if (sizeof((x == 2) ? f : i) == sizeof(float))
  8.             printf("float\n");
  9.         else if (sizeof((x == 2) ? f : i) == sizeof(short int))
  10.             printf("short int\n");
  11.     }
a) float
b) short int
c) Undefined behaviour
d) Compile time error
Answer:a
4. What is the output of this C code?
  1.     #include 
  2.     int main()
  3.     {
  4.         int a = 2;
  5.         int b = 0;
  6.         int y = (b == 0) ? a :(a > b) ? (b = 1): a;
  7.         printf("%d\n", y);
  8.     }
a) Compile time error
b) 1
c) 2
d) Undefined behaviour
Answer:c
5. What is the output of this C code?
  1.     #include 
  2.     int main()
  3.     {
  4.         int y = 1, x = 0;
  5.         int l = (y++, x++) ? y : x;
  6.         printf("%d\n", l);
  7.     }
a) 1
b) 2
c) Compile time error
d) Undefined behaviour
Answer:a
6. What is the output of this C code?
  1.     #include 
  2.     void main()
  3.     {
  4.         int k = 8;
  5.         int m = 7;
  6.         int z = k < m ? k++ : m++;
  7.         printf("%d", z);
  8.     }
a) 7
b) 8
c) Run time error
d) None of the mentioned
Answer:a
7. Comment on the output of this C code?
  1.     #include 
  2.     void main()
  3.     {
  4.         int k = 8;
  5.         int m = 7;
  6.         int z = k < m ? k = m : m++;
  7.         printf("%d", z);
  8.     }
a) Run time error
b) 7
c) 8
d) Depends on compiler
Answer:b
8. The code snippet below produces
  1.     #include 
  2.     void main()
  3.     {
  4.         1 < 2 ? return 1 : return 2;
  5.     }
a) returns 1
b) returns 2
c) Varies
d) Compile time error
Answer:d
9. The output of the code below is
  1.     #include 
  2.     void main()
  3.     {
  4.         int k = 8;
  5.         int m = 7;
  6.         k < m ? k++ : m = k;
  7.         printf("%d", k);
  8.     }
a) 7
b) 8
c) Compile time error
d) Run time error
Answer:c 
10. The output of the code below is
  1.     #include 
  2.     void main()
  3.     {
  4.         int k = 8;
  5.         int m = 7;
  6.         k < m ? k = k + 1 : m = m + 1;
  7.         printf("%d", k);
  8.     }
a) Compile time error
b) 9
c) 8
d) Run time error
Answer:a 
11. For initialization a = 2, c = 1 the value of a and c after this code will be
     c = (c) ? a = 0 : 2;

a) a = 0, c = 0;
b) a = 2, c = 2;
c) a = 2, c = 2;
d) a = 1, c = 2;
Answer:a 
12. What will be the data type of the expression (a < 50) ? var1 : var2;     provided a = int, var1 = double, var2 = float

a) int 
b) float 
c) double 
d) Cannot be determined
  Answer:c 

13. Which expression has to be present in the following?     exp1 ? exp2 : exp3;

a) exp1 
b) exp2 
c) exp3 
d) All of the mentioned
  Answer:d 

14. Value of c after the following expression (initializations a = 1, b = 2, c = 1):      c += (-c) ? a : b;

a) Syntax Error 
b) c = 1 
c) c = 2 
d) c = 3 
 Answer:c 

15. Comment on the following expression?     c = (n) ? a : b; can be rewritten as

a) if (!n)c = b;     else c = a; 
b) if (n <= 0)c = b;     else c = a; 
c) if (n > 0)c = a;
    else c = b;
d) All of the mentioned

Answer:a

Related

Java Multiple Choice Questions & Answers on Literals & Variables for Freshers

1. Which of these is long data type literal? a) 0x99fffLb) ABCDEFGc) 0x99fffad) 99671246 Answer:a Explanation:Data type long literals are appended by an upper or lowercase L. 0x99fffL is hexadeci...

Data Structure Questions and Answers on Sum of Digits of a Given Number using Recursion

1. Which of the following methods can be used to find the sum of digits of a number? a) Recursionb) Iterationc) Greedy algorithmd) Both recursion and iteration Answer: d Explanation: Both recu...

Java Multiple Choice Questions & Answers on Character and Boolean Data Types for Freshers

1. What is the numerical range of a char data type in Java? a) -128 to 127b) 0 to 256c) 0 to 32767d) 0 to 65535 Answer:d Explanation: Char occupies 16-bit in memory, so it supports 2^16 i:e from ...

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