wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

C programming Basics

Total questions: 40

Worksheet time: 20mins

Name
Class
Date
1.

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

a)

int 2x

b)

int _x

c)

float double

d)

char @num

2.

What is the correct format specifier for integer output?

a)

%i

b)

%d

c)

%c

d)

%f

3.

Which header file is required for printf() and scanf()?

(a)  

4.

Every C program must have which function?

a)

main()

b)

start()

c)

execute()

d)

program()

5.

What is the correct way to comment a single line?

a)

/* comment */

b)

// comment

c)

# comment

d)

-- comment

6.

The smallest individual unit in a program is called:

a)

Variable

b)

Function

c)

Token

d)

Operator

7.

What is the correct way to end a statement in C?

a)

.

b)

;

c)

:

d)

,

8.

Which of these is not a keyword in C?

a)

auto

b)

main

c)

static

d)

default

9.

The C language was developed by:

a)

Dennis Ritchie

b)

Charles Babbage

c)

James Gosling

d)

Guido van Rossum

10.

Which of the following is not a data type in C?

a)

int

b)

float

c)

real

d)

char

11.

The operator == is used for:

a)

Assignment

b)

Comparison

c)

Bitwise AND

d)

None

12.

What is the output of printf("%d", 5/2);?

a)

2.5

b)

2

c)

2.0

d)

Error

13.

Which operator has the highest precedence?

a)

+

b)

*

c)

=

d)

&&

14.

The remainder operator in C is:

a)

/

b)

%

c)

mod

d)

//

15.

Which of these is a logical operator?

a)

&&

b)

==

c)

+

d)

%

16.

What will be the output of this code? int x=0; if(x) printf("Hi"); else printf("Hello");

a)

Hi

b)

Hello

c)

Error

d)

No output

17.

The switch statement can work with which type?

a)

int

b)

float

c)

double

d)

all

18.

The keyword used to exit a loop immediately is:

a)

stop

b)

exit

c)

break

d)

return

19.

What is the output of this code? for(int i=0;i<3;i++); printf("%d",i);

a)

012

b)

3

c)

2

d)

Error

20.

The loop that executes at least once is:

a)

for

b)

while

c)

do-while

d)

nested for

21.

Correct declaration of an array:

a)

int arr[5];

b)

int arr;[5]

c)

int arr[]5;

d)

arr int[5];

22.

The last index of an array of size 10 is:

a)

10

b)

9

c)

11

d)

Undefined

23.

Which function finds the length of a string?

a)

strlen()

b)

strsize()

c)

size()

d)

len()

24.

What is the null character in C strings?

a)

' '

b)

' '

c)

' '

d)

'0'

25.

Which header is required for string functions?

a)

b)

c)

d)

26.

Correct function declaration:

a)

function add(int a,int b);

b)

int add(int a,int b);

c)

declare add(int,int);

d)

void add a,b;

27.

Which keyword is used to return a value from a function?

a)

return

b)

break

c)

goto

d)

exit

28.

What is the default return type of a function in C (if not specified)?

a)

float

b)

void

c)

int

d)

double

29.

A function that calls itself is called:

a)

inline function

b)

recursion

c)

nested

d)

reentrant

30.

The value passed to a function is called:

a)

argument

b)

variable

c)

pointer

d)

macro

31.

A pointer stores:

a)

a value

b)

an address

c)

both

d)

none

32.

Which operator gives the address of a variable?

a)

*

b)

&

c)

->

d)

%

33.

Which function dynamically allocates memory?

a)

alloc()

b)

malloc()

c)

new()

d)

calloc()

34.

If int *p; and int a=10; p=&a;, what does *p give?

a)

address of a

b)

10

c)

garbage

d)

error

35.

Which function releases dynamically allocated memory?

a)

remove()

b)

delete()

c)

free()

d)

release()

36.

Output of:

int a=5;

printf("%d %d", a++, ++a);

a)

5 7

b)

6 7

c)

Undefined

d)

5 6

37.

What will happen if you print an uninitialized variable?

a)

Prints 0

b)

Prints garbage

c)

Error

d)

Stops execution

38.

Which keyword is used to define constants?

a)

constant

b)

final

c)

#define

d)

const

39.

What will be the output of this code? int x=1; do { printf("%d ", x); x++; } while(x<1);

a)

1

b)

No output

c)

Infinite

d)

Error

40.

What is the output of the following code? printf("%d", sizeof('A'));

a)

1

b)

2

c)

4

d)

Depends on system