Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

C Programming Concepts Challenge

Total questions: 25

Worksheet time: 2hrs 5mins

Name
Class
Date
1.

What is the correct syntax to define a function in C?

a)

return_type function_name(parameter_type parameter_name) { // function body }

b)

return_type { function_name(parameter_type parameter_name) }

c)

function_name { return_type parameter_type parameter_name }

d)

function_name(parameter_type) return_type { // function body }

2.

How do you declare an array of integers in C?

a)

int arr(10);

b)

int array[10];

c)

array int arr[10];

d)

int arr[10];

3.

What will be the output of the following loop: for(int i=0; i<5; i++) printf("%d ", i);?

a)

1 2 3 4 5

b)

0 1 2 3 4

c)

0 1 2 3

d)

-1 0 1 2 3

4.

What is the purpose of the 'break' statement in a loop?

a)

To exit a loop prematurely.

b)

To restart the loop from the beginning.

c)

To skip the current iteration of the loop.

d)

To pause the loop temporarily.

5.

How do you access the third element of an array named 'arr'?

a)

arr(2)

b)

arr{2}

c)

arr[3]

d)

arr[2]

6.

What will the following code output: if(5 > 3) printf("True"); else printf("False");?

a)

True

b)

Maybe

c)

False

d)

Definitely not

7.

What is the result of the following pointer arithmetic: int *p; p = arr; p++;?

a)

p is uninitialized and cannot be used.

b)

p now points to the second element of the array (arr[1]).

c)

p now points to the first element of the array (arr[0]).

d)

p now points to the third element of the array (arr[2]).

8.

How do you declare a function that takes an array as a parameter?

a)

function myFunction(array) { // code here }

b)

myFunction(arr) => { // code here }

c)

function myFunction(arr: Array) { // code here }

d)

function myFunction(arr) { // code here }

9.

What is the output of the following code snippet: int a = 10; if(a == 10) printf("Equal"); else printf("Not Equal");?

a)

Not Equal

b)

Equal to 15

c)

Equal to 5

d)

Equal

10.

What is the difference between a while loop and a do-while loop?

a)

A while loop executes at least once before checking the condition; a do-while loop checks the condition first.

b)

A while loop can only be used with integer values; a do-while loop can use any data type.

c)

A while loop checks the condition before execution; a do-while loop executes at least once before checking the condition.

d)

A while loop is used for infinite loops; a do-while loop is used for conditional loops.

11.

How do you initialize a pointer to the first element of an array?

a)

int *ptr = &arr[0];

b)

int *ptr = arr;

c)

int ptr = arr[0];

d)

int *ptr = arr + 1;

12.

What will the following code print: for(int i=0; i<3; i++) { if(i == 1) continue; printf("%d ", i); }?

a)

0 1

b)

0 1 2

c)

0 2

d)

1 2

13.

What is the syntax to declare a pointer to a function in C?

a)

int (*ptr[])(int, int);

b)

int (*ptr)(int, int);

c)

int ptr(int, int);

d)

int *ptr(int, int);

14.

What will happen if you try to access an array element out of its bounds?

a)

An error or undefined behavior occurs.

b)

The program will automatically fix the error.

c)

The value will be set to zero.

d)

The array will expand to accommodate the new index.

15.

How do you use a pointer to swap two integers in a function?

a)

void swap(int *a, int *b) { int temp = *a; *a = *b; *b = temp; }

b)

void swap(int a, int b) { int temp = a; a = b; b = temp; return; }

c)

void swap(int *a, int b) { *a = b; }

d)

void swap(int a, int b) { int temp = a; a = b; b = temp; }

16.

What is the correct way to allocate memory for an array of 10 integers in C?

a)

int *arr = malloc(10 * sizeof(int));

b)

int arr = malloc(10 * sizeof(int));

c)

int arr[10] = malloc(sizeof(int) * 10);

d)

int *arr = new int[10];

17.

What will the following code output: for(int i=0; i<5; i++) { if(i == 3) break; printf("%d ", i); }?

a)

0 1 2 3 4

b)

0 1 2

c)

1 2 3

d)

0 1 2 3

18.

What is the output of the following code snippet: int x = 5; int y = 10; printf("%d", x + y);?

a)

50

b)

15

c)

5

d)

10

19.

How do you declare a constant in C?

a)

constant int x = 10;

b)

int x = const 10;

c)

int const x = 10;

d)

const int x = 10;

20.

What will the following code output: for(int i=0; i<3; i++) { if(i == 1) continue; printf("%d ", i); }?

a)

1 2

b)

0 1

c)

0 2

d)

0 1 2

21.

What is the output of the following code snippet: int a = 5; int b = 2; printf("%d", a / b);?

a)

5

b)

3

c)

2.5

d)

2

22.

What will the following code output: for(int i=0; i<4; i++) { if(i == 2) continue; printf("%d ", i); }?

a)

0 1

b)

1 2 3

c)

0 1 3

d)

0 1 2 3

23.

What will the following code output: for(int i=0; i<5; i++) { if(i == 4) break; printf("%d ", i); }?

a)

1 2 3 4

b)

0 1 2 3

c)

0 1 2 3 4

d)

0 1 2 3 4 5

24.

How do you declare a function that returns a pointer to an integer?

a)

int *myFunction();

b)

int myFunction*();

c)

myFunction() -> int *;

d)

function int *myFunction();

25.

What is the output of the following code snippet: int a = 3; int b = 4; printf("%d", a + b * 2);?

a)

14

b)

8

c)

11

d)

7