wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Can you C?

Total questions: 5

Worksheet time: 2mins

Name
Class
Date
1.

What will be the output of the following C code?

#include <stdio.h>

void main()

{

char *str = "";

do

{

printf("hello");

} while (str);

}

a)

Nothing

b)

Run time Error

c)

Hello is printed infinite times

d)

Hello is printed one time

2.

How many times while loop condition is tested in the following C code snippets, if i is initialized to 0 in both the cases?


1.

while (i < n)

i++;


2.

do

i++;

while (i <= n);

a)

n, n

b)

n, n+1

c)

n+1, n

d)

n+1, n+1

3.

What will be the output of the following C code?


#include <stdio.h>

int main()

{

int i = 0;

while (i = 0)

printf("True\n");

printf("False\n");

}

a)

True (infinite time)

b)

True (1 time) False

c)

False

d)

Compiler dependent

4.

#include <stdio.h>

void main()

{

int a = 5, b = -7, c = 0, d;

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

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

}

a)

6 -6 0 0

b)

6 -5 0 1

c)

-6 -6 0 1

d)

6 -6 0 1

5.

#include <stdio.h>

int main()

{

int x = -2;

x = x >> 1;

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

}

a)

1

b)

-1

c)

2^31 – 1 considering int to be 4 bytes

d)

Either -1 or 1