MCQ Computer Science

C Programming Questions and Answers – Conditional Expressions – 1

C Programming Questions and Answers – Conditional Expressions – 1

This section on C interview questions and answers focuses on “Conditional Expressions”. One shall practice these interview questions to improve their C programming skills needed for various interviews (campus interviews, walking interviews, company interviews), placements, entrance exams and other competitive exams. These questions can be attempted by anyone focusing on learning C Programming language. They can be a beginner, fresher, engineering graduate or an experienced IT professional. Our C Interview questions come with detailed explanation of the answers which helps in better understanding of C concepts.
Here is a listing of C interview questions on “Conditional Expressions” along with answers, explanations and/or solutions:

1. What is the output of this C code?

#include <stdio.h>
int main()
{
int x = 2, y = 0;
int z = (y++) ? y == 1 && x : 0;
printf(“%d\n”, z);
return 0;
}
a) 0
b) 1
c) Undefined behaviour
d) Compile time error

View Answer

Answer:a

2. What is the output of this C code?

#include <stdio.h>
int main()
{
int x = 1;
int y = x == 1 ? getchar(): 2;
printf(“%d\n”, y);
}
a) Compile time error
b) Whatever character getchar function returns
c) Ascii value of character getchar function returns
d) 2

View Answer

Answer:c
3. What is the output of this C code?

#include <stdio.h>
int main()
{
int x = 1;
short int i = 2;
float f = 3;
if (sizeof((x == 2) ? f : i) == sizeof(float))
printf(“float\n”);
else if (sizeof((x == 2) ? f : i) == sizeof(short int))
printf(“short int\n”);
}
a) float
b) short int
c) Undefined behaviour
d) Compile time error

View Answer

Answer:a

4. What is the output of this C code?

#include <stdio.h>
int main()
{
int a = 2;
int b = 0;
int y = (b == 0) ? a :(a > b) ? (b = 1): a;
printf(“%d\n”, y);
}
a) Compile time error
b) 1
c) 2
d) Undefined behaviour

View Answer

Answer:c

5. What is the output of this C code?

#include <stdio.h>
int main()
{
int y = 1, x = 0;
int l = (y++, x++) ? y : x;
printf(“%d\n”, l);
}
a) 1
b) 2
c) Compile time error
d) Undefined behaviour

View Answer

Answer:a

6. What is the output of this C code?

#include <stdio.h>
void main()
{
int k = 8;
int m = 7;
int z = k < m ? k++ : m++;
printf(“%d”, z);
}
a) 7
b) 8
c) Run time error
d) None of the mentioned

View Answer

Answer:a

7. Comment on the output of this C code?

#include <stdio.h>
void main()
{
int k = 8;
int m = 7;
int z = k < m ? k = m : m++;
printf(“%d”, z);
}
a) Run time error
b) 7
c) 8
d) Depends on compiler

View Answer

Answer:b

8. The code snippet below produces

#include <stdio.h>
void main()
{
1 < 2 ? return 1 : return 2;
}
a) returns 1
b) returns 2
c) Varies
d) Compile time error

View Answer

Answer:d

For more Visit the Link:

Computer Science MCQ All Topic C programming MCQ All Topic

 

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button