wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Arrays and Pointers in C

Total questions: 15

Worksheet time: 20mins

Name
Class
Date
1.

What is the syntax for declaring an array in C?

a)

array_name = [array_size];

b)

array_name = data_type[array_size];

c)

array_name[array_size] = data_type;

d)

data_type array_name[array_size];

2.

What is the syntax for declaring a pointer in C?

a)

int ptr;

b)

ptr = int;

c)

int *ptr();

d)

int *ptr;

3.

How is pointer arithmetic performed in C?

a)

By dividing the pointer by an integer value

b)

By multiplying the pointer with an integer value

c)

By adding or subtracting an integer value to/from a pointer

d)

By performing bitwise operations on the pointer

4.

What is the difference between array and pointer in C?

a)

Arrays are a fixed-size collection of elements, while pointers are variables that store memory addresses.

b)

Arrays cannot be passed as arguments to functions, while pointers can

c)

Arrays can only store integers, while pointers can store any data type

d)

Arrays and pointers are the same thing

5.

Explain the concept of passing an array to a function in C.

a)

Passing an array to a function in C only allows access to the first element of the array

b)

Passing an array to a function in C allows the function to work with the elements of the array.

c)

Passing an array to a function in C is not possible

d)

Passing an array to a function in C allows the function to modify the size of the array

6.

How can you dynamically allocate memory for an array using pointers in C?

a)

Use the 'realloc' function

b)

Use the 'malloc' function

c)

Use the 'free' function

d)

Use the 'calloc' function

7.

What is the purpose of the 'const' keyword in C?

a)

To declare a constant variable that cannot be modified

b)

To declare a variable that can only be modified within a specific function

c)

To declare a variable that can be modified by any function

d)

To declare a variable that can be modified by any other variable

8.

Explain the concept of dynamic memory allocation in C.

a)

Dynamic memory allocation in C allows the program to allocate memory at compile time

b)

Dynamic memory allocation in C allows the program to allocate memory at runtime

c)

Dynamic memory allocation in C is not possible

d)

Dynamic memory allocation in C allows the program to allocate memory for global variables only

9.

What is the purpose of the 'static' keyword in C?

a)

To declare a variable that can be accessed only within the same function

b)

To declare a variable that retains its value between function calls

c)

To declare a variable that can be modified by any other variable

d)

To declare a variable that can only be modified within a specific function

10.

What is the syntax for declaring a multi-dimensional array in C?

a)

data_type array_name[array_size1][array_size2];

b)

array_name = data_type[array_size1][array_size2];

c)

array_name = [array_size1][array_size2];

d)

data_type[array_size1][array_size2] array_name;

11.

Write the array declaration syntax for the items below
name: a

values: 2,1,3,5,4

4 lines
12.

Write the array declaration syntax for the items below (dynamic array declaration)
name: b

values: 0,2,4,6,8

4 lines
13.

Write the array declaration syntax for the items below (use realloc)
name: b

values: 0,2,4,6,8, 1, 3, 5, 7, 9

4 lines
14.

void minMaxAve (int *, int, int)

Given the prototype above, write the appropriate function header.

4 lines
15.

void minMaxAve (int *, int, int)

Given the prototype above, write the appropriate function call.

4 lines