wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

C-technical Quiz 1

Total questions: 15

Worksheet time: 16mins

Name
Class
Date
1.

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)

Runtime error

2.

What will be the output of the following C code?

#include <stdio.h>

int main()

{

signed char chr;

chr = 128;

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

return 0;

}

a)

128

b)

-128

c)

Depends on the compiler

d)

None

3.

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

4.

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

5.

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

Some garbage value

c)

4

d)

Undefined behaviour

6.

What will be the output of the following C code?

#include <stdio.h>

int main()

{

int a = -1, b = 4, c = 1, d;

d = ++a && ++b || ++c;

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

return 0;

}

a)

0, 4, 2, 1

b)

0, 5, 2, 1

c)

-1, 4, 1, 1

d)

0, 5, 1, 0

7.

What will be the output of the following C code? (Initial values: x= 7, y = 8)

#include <stdio.h>

void main()

{

float x;

int y;

printf("enter two numbers \n");

scanf("%f %f", &x, &y);

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

}

a)

7.000000, 7

b)

Run time error

c)

7.000000, junk

d)

Varies

8.

What will be the output of the following C code?

#include <stdio.h>

void main()

{

int i = 0;

int j = 0;

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

{

for (j = 0;j < 4; j++)

{

if (i > 1)

continue;

printf("Hi \n");

}

}

}

a)

Hi is printed 9 times

b)

Hi is printed 8 times

c)

Hi is printed 7 times

d)

Hi is printed 6 times

9.

The C statement “”if (a == 1 || b == 2) {}”” can be re-written as ___________

a)

if (a == 1) if (b == 2){}

b)

if (a == 1){} if (b == 2){}

c)

if (a == 1){} else if (b == 2){}

d)

none of the mentioned

10.

Which of the following option is the correct representation of the following C statement?

e = a b + c / d f;

a)

e = (a (b +(c /(d f))));

b)

e = ((a b) + (c / (d f)));

c)

e = ((a b) + ((c / d) f));

d)

Both e = ((a b) + (c / (d f))); and e = ((a b) + ((c / d) f));

11.

What will be the output of the following C code?

#include <stdio.h>

void main()

{

int h = 8;

int b = h++ + h++ + h++;

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

}

a)

9

b)

10

c)

12

d)

11

12.

What will be the output of the following C code?

#include <stdio.h>

void main()

{

char a = 'A';

char b = 'B';

int c = a + b % 3 - 3 * 2;

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

}

a)

65

b)

58

c)

64

d)

59

13.

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

14.

What will be the output of the following C code?

#include <stdio.h>

void main()

{

double x = 123828749.66;

int y = x;

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

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

}

a)

0, 0.0

b)

123828749, 123828749.66

c)

12382874, 12382874.0

d)

123828749, 0.000000

15.

What will be the output of the following C code?

#include <stdio.h>

int main()

{

unsigned int i = 23;

signed char c = -23;

if (i > c)

printf("Yes\n");

else if (i < c)

printf("No\n");

}

a)

Yes

b)

No

c)

Depends on the compiler

d)

Depends on the operating system