0% found this document useful (0 votes)
83 views19 pages

Day 2 - Operators (Answers)

The document contains a series of questions and answers related to C programming, covering topics such as operator precedence, data types, and output of specific code snippets. Each question is followed by multiple-choice answers, with the correct answer indicated. The questions assess knowledge of C syntax, behavior of operators, and the effects of various expressions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
83 views19 pages

Day 2 - Operators (Answers)

The document contains a series of questions and answers related to C programming, covering topics such as operator precedence, data types, and output of specific code snippets. Each question is followed by multiple-choice answers, with the correct answer indicated. The questions assess knowledge of C syntax, behavior of operators, and the effects of various expressions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 19

1. What will be the output of the following C code?

#include <stdio.h>

void main()

int a = 3;

int b = ++a + a++ + --a;

printf("Value of b is %d", b);

a) Value of x is 12

b) Value of x is 13

c) Value of x is 10

d) Undefined behaviour/Compiler dependent

Answer: d

2. What is the precedence of arithmetic operators (from highest to lowest)?

a) %, *, /, +, –

b) %, +, /, *, –

c) +, -, %, *, /

d) %, +, -, *, /

Answer: a

3. Which of the following is not an arithmetic operation?

a) a * = 10;

b) a / = 10;

c) a ! = 10;

d) a % = 10;

Answer: c
4. Which of the following data type will throw an error on modulus operation(%)?

a) char

b) short

c) int

d) float

Answer: d

5. What will be the output of the following C code?

#include <stdio.h>

int main()

int a = 10;

double b = 5.6;

int c;

c = a + b;

printf("%d", c);

a) 15

b) 16

c) 15.6

d) 10

Answer: a

6. What will be the output of the following C code?

#include <stdio.h>

int main()
{

int a = 10, b = 5, c = 5;

int d;

d = a == (b + c);

printf("%d", d);

a) Syntax error

b) 1

c) 10

d) 5

Answer: b

7. What will be the output of the following C code?

#include <stdio.h>

int main()

int i = 3;

int l = i / -2;

int k = i % -2;

printf("%d %d\n", l, k);

return 0;

a) Compile time error

b) -1 1

c) 1 -1

d) Implementation defined
Answer: b

8. What will be the output of the following C code?

#include <stdio.h>

int main()

int i = 5;

i = i / 3;

printf("%d\n", i);

return 0;

a) Implementation defined

b) 1

c) 3

d) Compile time error

Answer: b

9. What will be the output of the following C code?

#include <stdio.h>

void main()

int x = 5.3 % 2;

printf("Value of x is %d", x);

a) Value of x is 2.3

b) Value of x is 1

c) Value of x is 0.3
d) Compile time error

Answer: d

10. What will be the output of the following C code?

#include <stdio.h>

void main()

int x = 1, y = 0, z = 5;

int a = x && y || z++;

printf("%d", z);

a) 6

b) 5

c) 0

d) Varies

Answer: a

11. What will be the output of the following C code?

#include <stdio.h>

void main()

int x = 1, y = 0, z = 5;

int a = x && y && z++;

printf("%d", z);

a) 6

b) 5
c) 0

d) Varies

Answer: b

12. What will be the output of the following C code?

#include <stdio.h>

int main()

int x = 1, y = 0, z = 3;

x > y ? printf("%d", z) : return z;

a) 3

b) 1

c) Compile time error

d) Run time error

Answer: c

13. What will be the output of the following C code?

#include <stdio.h>

void main()

int x = 1, z = 3;

int y = x << 3;

printf(" %d\n", y);

a) -2147483648

b) -1
c) Run time error

d) 8

Answer: d

14. What will be the output of the following C code?

#include <stdio.h>

void main()

int x = 0, y = 2, z = 3;

int a = x & y | z;

printf("%d", a);

a) 3

b) 0

c) 2

d) Run time error

Answer: a

15. What will be the final value of j in the following C code?

#include <stdio.h>

int main()

int i = 0, j = 0;

if (i && (j = i + 10))

//do something

}
a) 0

b) 10

c) Depends on the compiler

d) Depends on language standard

Answer: a

16. What will be the output of the following C code?

#include <stdio.h>

int main()

int i = 1;

if (i++ && (i == 1))

printf("Yes\n");

else

printf("No\n");

a) Yes

b) No

c) Depends on the compiler

d) Depends on the standard

Answer: b

17. What is the result of logical or relational expression in C?

a) True or False

b) 0 or 1

c) 0 if an expression is false and any positive number if an expression is true

d) None of the mentioned


Answer: b

18. What will be the output of the following C code?

#include <stdio.h>

int main()

int a = 10, b = 5, c = 3;

b != !a;

c = !!a;

printf("%d\t%d", b, c);

a) 5 1

b) 0 3

c) 5 3

d) 1 1

Answer: a

19. Which among the following is NOT a logical or relational operator?

a) !=

b) ==

c) ||

d) =

Answer: d

20. What will be the output of the following C code?

#include <stdio.h>

int main()

{
int c = 2 ^ 3;

printf("%d\n", c);

a) 1

b) 8

c) 9

d) 0

Answer: a

21. What will be the output of the following C code?

#include <stdio.h>

int main()

unsigned int a = 10;

a = ~a;

printf("%d\n", a);

a) -9

b) -10

c) -11

d) 10

Answer: c

22. What will be the output of the following C code?

#include <stdio.h>

int main()

{
int a = 2;

if (a >> 1)

printf("%d\n", a);

a) 0

b) 1

c) 2

d) No Output

Answer: c

23. What will be the output of the following C code?

#include <stdio.h>

void main()

int x = 97;

int y = sizeof(x++);

printf("x is %d", x);

a) x is 97

b) x is 98

c) x is 99

d) Run time error

Answer: a

24. What will be the output of the following C code?

#include <stdio.h>

void main()
{

int x = 4, y, z;

y = --x;

z = x--;

printf("%d%d%d", x, y, z);

a) 3 2 3

b) 2 2 3

c) 3 2 2

d) 2 3 3

Answer: d

25. What will be the output of the following 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

Answer: a
26. What will be the output of the following 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

Answer: a

27. What will be the output of the following 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

Answer: c

28. What will be the output of the following 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

Answer: a

29. What will be the output of the following C code?

#include <stdio.h>

void main()

1 < 2 ? return 1 : return 2;

}
a) returns 1

b) returns 2

c) Varies

d) Compile time error

Answer: d

30. What will be the final values of a and c in the following C statement? (Initial values: a = 2, c = 1)

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

31. What is the type of the following assignment expression if x is of type float and y is of type int?

y = x + y;

a) int

b) float

c) there is no type for an assignment expression

d) double

Answer: a

32. Operation “a = a * b + a” can also be written as ___________

a) a *= b + 1;

b) (c = a * b)!=(a = c + a);

c) a = (b + 1)* a;

d) All of the mentioned

Answer: d
33. What will be the final value of c in the following C statement? (Initial value: c = 2)

c <<= 1;

a) c = 1;

b) c = 2;

c) c = 3;

d) c = 4;

Answer: d

34. What will be the output of the following C code?

#include <stdio.h>

void main()

int a = 2 + 4 + 3 * 5 / 3 - 5;

printf("%d", a);

a) 7

b) 6

c) 10

d) 9

Answer: b

35. What will be the output of the following C code?

#include <stdio.h>

void main(

double b = 8;

b++;
printf("%lf", b);

a) 9.000000

b) 9

c) 9.0

d) Run time error

Answer: a

36. What will be the output of the following C code?

#include <stdio.h>

void main()

double b = 5 % 3 & 4 + 5 * 6;

printf("%lf", b);

a) 2

b) 30

c) 2.000000

d) Run time error

Answer: c

37. What will be the output of the following 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

Answer: b

38. What will be the output of the following 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

Answer: a

39. What will be the output of the following C code?

#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

Answer: a

40. What will be the output of the following 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

Answer: b

You might also like