Computer StudyMCQ Computer ScienceQuiz Computer ScienceUGC NET

C Programming Questions and Answers – Assigment Operators & Expressions 

C Programming Questions and Answers – Assigment Operators & Expressions

1.What is the output of this C code?

 

#include <stdio.h>

void main()

{

int x = 0;

if (x = 0)

printf(“Its zero\n”);

else

printf(“Its not zero\n”);

}

a) Its not zero

b) Its zero

c) Run time error

d) None

 

View Answer

Answer:a

 

2.What is the output of this C code?

 

#include <stdio.h>

void main()

{

int k = 8;

int x = 0 == 1 && k++;

printf(“%d%d\n”, x, k);

}

a) 0 9

b) 0 8

c) 1 8

d) 1 9

 

View Answer

Answer:b

 

3.What is the output of this C code?

 

#include <stdio.h>

void main()

{

char a = ‘a’;

int x = (a % 10)++;

printf(“%d\n”, x);

}

a) 6

b) Junk value

c) Compile time error

d) 7

 

View Answer

Answer:c

 

4.What is the output of this 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

 

View Answer

Answer:d

 

5.What is the output of this C code?

 

#include <stdio.h>

void main()

{

unsigned int x = -5;

printf(“%d”, x);

}

a) Run time error

b) Aries

c) -5

d) 5

 

View Answer

Answer:c

 

6.What is the output of this C code?

 

#include <stdio.h>

int main()

{

int x = 2, y = 1;

x *= x + y;

printf(“%d\n”, x);

return 0;

}

a) 5

b) 6

c) Undefined behaviour

d) Compile time error

 

View Answer

Answer:b

 

7.What is the output of this C code?

 

#include <stdio.h>

int main()

{

int x = 2, y = 2;

x /= x / y;

printf(“%d\n”, x);

return 0;

}

a) 2

b) 1

c) 0.5

d) Undefined behaviour

 

View Answer

Answer:a

 

8.What is the output of this C code?

 

#include <stdio.h>

int main()

{

int x = 1, y = 0;

x &&= y;

printf(“%d\n”, x);

}

a) Compile time error

b) 1

c) 0

d) Undefined behaviour

 

View Answer

Answer:a

 

9.What is the type of the below assignment expression if x is of type float, y is of type int?

y = x + y;

a) int

b) float

c) There is no type for an assignment expression

d) double

 

View Answer

Answer:a

 

10.What is the value of the below assignment expression

(x = foo())!= 1 considering foo() returns 2

a) 2

b) True

c) 1

d) 0

 

View Answer

Answer:a

 

11.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

 

View Answer

Answer:d

 

12.for c = 2, value of c after c <<= 1;

a) c = 1;

b) c = 2;

c) c = 3;

d) c = 4;

 

View Answer

Answer:d

 

 

13.What is the output of this C code?

 

#include <stdio.h>

int main()

{

int a = 1, b = 2;

a += b -= a;

printf(“%d %d”, a, b);

}

a) 1 1

b) 1 2

c) 2 1

d) 2 2

 

View Answer

Answer:c

 

14.What is the output of this C code?

 

#include <stdio.h>

int main()

{

int a = 4, n, i, result = 0;

scanf(“%d”, n);

for (i = 0;i < n; i++)

result += a;

}

a) Addition of a and n.

b) Subtraction of a and n.

c) Multiplication of a and n.

d) Division of a and n.

 

View Answer

Answer:c

 

15.Which of the following is an invalid assignment operator?

a) a %= 10;

b) a /= 10;

c) a |= 10;

d) None of the mentioned

 

View Answer

Answer:d

Related Articles

Leave a Reply

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

Back to top button