MCQ Computer Science

C Programming Questions and Answers – Precedence and Order of Evaluation – 2

C Programming Questions and Answers – Precedence and Order of Evaluation – 2

Sanfoundry’s 1000+ Interview Questions & Answers on C helps anyone preparing for VMware and other companies C interviews. One should practice these 1000+ interview questions and answers continuously for 2-3 months to clear VMware interviews on C Programming language.
Here is a listing of online C test questions on “Precedence and Order of Evaluation” 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 = 2;
float f = y + x /= x / y;
printf(“%d %f\n”, x, f);
return 0;
}
a) 2 4.000000
b) Compile time error
c) 2 3.500000
d) Undefined behaviour

View Answer

Answer:b

2. What is the output of this C code?

#include <stdio.h>
int main()
{
int x = 1, y = 2;
if (x && y == 1)
printf(“true\n”);
else
printf(“false\n”);
}
a) true
b) false
c) Compile time error
d) Undefined behaviour

View Answer

Answer:b

3. What is the output of this C code?

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

View Answer

Answer:b

4. What is the output of this C code?

#include <stdio.h>
int main()
{
int x = 3, y = 2;
int z = x /= y %= 2;
printf(“%d\n”, z);
}
a) 1
b) Compile time error
c) Floating point exception
d) Segmentation fault

View Answer

Answer:c

5. What is the output of this C code?

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

View Answer

Answer:a

6. What is the output of this C code?

#include <stdio.h>
int main()
{
int x = 3; //, y = 2;
const int *p = &x;
*p++;
printf(“%d\n”, *p);
}
a) Increment of read-only location compile error
b) 4
c) Some garbage value
d) Undefined behaviour

View Answer

Answer:c

7. What is the output of this C code?

#include <stdio.h>
int main()
{
int x = 2, y = 2;
int z = x ^ y & 1;
printf(“%d\n”, z);
}
a) 1
b) 2
c) 0
d) 1 or 2

View Answer

Answer:b

8. What is the output of this C code?

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

View Answer

Answer:c

9. What is the output of the code given below

#include <stdio.h>
int main()
{
int x = 0, y = 2;
if (!x && y)
printf(“true\n”);
else
printf(“false\n”);
}
a) true
b) false
c) Compile time error
d) Undefined behaviour

View Answer

Answer:a

10. What is the output of this C code?

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

View Answer

Answer:b

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