wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

C Programming Unit-1 Test-2

Total questions: 20

Worksheet time: 29mins

Name
Class
Date
1.

Which of the following is not a valid C variable name?

a)

int number;

b)

float rate;

c)

int variable_count;

d)

int $main;

2.

Which of the following is true for variable names in C?

a)

They can contain alphanumeric characters as well as special characters

b)

It is not an error to declare a variable to be one of the keywords(like goto, static)

c)

Variable names cannot start with a digit

d)

Variable can be of any length

3.

What is short int in C programming?

a)

The basic data type of C

b)

Qualifier

c)

Short is the qualifier and int is the basic data type

d)

All of the mentioned

4.

Which of the following typecasting is accepted by C language?

a)

Widening conversions

b)

Narrowing conversions

c)

Widening & Narrowing conversions

d)

None of the mentioned

5.

Which of the following is NOT possible with any 2 operators in C?

a)

Different precedence, same associativity

b)

Different precedence, different associativity

c)

Same precedence, different associativity

d)

All of the mentioned

6.

Property which allows to produce different executable for different platforms in C is called?

a)

File inclusion

b)

Selective inclusion

c)

Conditional compilation

d)

Recursive macros

7.

What will be the output of the following C code?

int y = 10000;

int y = 34;

printf("Hello World! %d\n", y);

a)

Hello World! 34

b)

Hello World! 10000

c)

Hello World! followed by a junk value

d)

Compile time error

8.

What will be the output of the following C code?

signed char chr;

chr = 128;

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

a)

128

b)

-128

c)

Depends on the compiler

d)

None

9.

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

float x;

int y;

printf("enter two numbers \n", x);

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

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

a)

7.000000, 8

b)

Run time error

c)

7.000000, junkvalue

d)

Varies

10.

What is the range of values that can be stored by int datatype in C?

a)

-(2^31) to (2^31) - 1.

b)

-256 to 255

c)

-(2^63) to (2^63)-1

d)

0 to (2^31)-1

11.

Which of the following is an exit controlled loop?

a)

while

b)

for

c)

do-while

d)

switch

12.

What will be the result of the following code snippet?

char ch[10] = "abcdefghij";

int ans = 0;

for(int i = 0; i < 10; i++) {

ans += (ch[i] - 'a'); }

printf("%d", ans);

a)

45

b)

36

c)

20

d)

100

13.

What will be the output of the following code snippet?

int ch = 2;

switch(ch) {

case 1: printf("1 ");

case 2: printf("2 ");

case 3: printf("3 ");

default: printf("None"); }

a)

1 2 3 None

b)

2

c)

2 3 None

d)

None

14.

What will be the output of the following code snippet?

int x = 1,

y = 2;

printf(x > y ? "Greater" : x == y ? "Equal" : "Lesser");

a)

Greater

b)

Lesser

c)

Equal

d)

None

15.

What will be the output of the following code snippet?

printf("%d ", 9 / 2);

printf("%f", 9.0 / 2);

a)

4 4.5000

b)

4 4.000

c)

4.5000 4.5000

d)

4 4

16.

What will be the output of the following code snippet?

int x = 2;

printf("%d", (x << 1) + (x >> 1));

a)

5

b)

4

c)

2

d)

1

17.

Determine the output of the C code mentioned below:

float q = ‘a’;

printf(“%f”, q);

a)

run time error

b)

a

c)

97.000000

d)

a.0000000

18.

Which bitwise operator is suitable for turning 'off' and 'on' a particular bit in a number?

a)

&& &

b)

& |

c)

! !

d)

| &

19.

What will you do to treat the constant 3.14 as a long double?

a)

use 3.14LD

b)

use 3.14L

c)

use 3.14DL

d)

use 3.14LF

20.

float x = 3.6;

int y = ?

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

Find the expression for y to get result as 4

a)

y = (int)(x + 0.5)

b)

y = int(x + 0.5)

c)

y = (int)x + 0.5

d)

None