Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Quiz on Arrays in Programming

Total questions: 45

Worksheet time: 23mins

Name
Class
Date
1.

What is an array in programming?

a)

A collection of similar data items stored under a common name

b)

A single data item stored in a variable

c)

A function that performs operations on data

d)

A type of loop used in programming

2.

How are uninitialized elements in an array handled in C?

a)

They are set to one

b)

They are automatically initialized to zero

c)

They are left undefined

d)

They are initialized to null

3.

What is the difference between single-dimensional and two-dimensional arrays?

a)

Single-dimensional arrays store data in rows and columns

b)

Two-dimensional arrays store data in a linear sequence

c)

Single-dimensional arrays store data in a linear sequence

d)

Two-dimensional arrays store data in a single line

4.

How can you declare an array in C?

a)

data_type array_name[size];

b)

array_name[size] data_type;

c)

data_type[size] array_name;

d)

array_name data_type[size];

5.

Which of the following is a method to initialize a string in C?

a)

Using a loop

b)

Using a string literal

c)

Using a pointer

d)

Using a function

6.

What are two functions in the C string library?

a)

printf(), scanf()

b)

strlen(), strcpy()

c)

malloc(), free()

d)

fopen(), fclose()

7.

Exemplify the string function used to concatenate two strings in C.

a)

strcpy

b)

strcat

c)

strcmp

d)

strlen

8.

Define a function. Write syntax for function declaration and call.

a)

A function is a block of statements that performs a specific task. Syntax: int add(int x, int y);

b)

A function is a variable that stores data. Syntax: int add = 5;

c)

A function is a loop that iterates over a block of code. Syntax: for(int i=0; i<10; i++);

d)

A function is a conditional statement. Syntax: if(x > y)

9.

What is the difference between actual and formal parameters?

a)

Actual parameters are used in function definition; formal parameters are used in function call.

b)

Actual parameters are stored in the called function; formal parameters are stored in the calling function.

c)

Actual parameters are stored in the calling function; formal parameters are stored in the called function.

d)

Actual parameters are variables; formal parameters are constants.

10.

List out the advantage of using user-defined functions.

a)

Increase the source code

b)

Difficult to maintain and modify

c)

Reduce the source code

d)

Cannot be called from anywhere in the program

11.

List out the categories of functions.

a)

Functions with arguments and no return values

b)

Functions with no arguments and no return values

c)

Functions with arguments and with return values

d)

All of the above

12.

Define a structure with an example.

a)

A structure is a single variable of one data type. Example: int number;

b)

A structure is a collection of variables of different data types. Example: struct student { char name[20]; int ID; }

c)

A structure is a loop that iterates over a block of code. Example: for(int i=0; i<10; i++);

d)

A structure is a conditional statement. Example: if(x > y)

13.

Differentiate between structures and unions with an example.

a)

Structures have shared memory; unions have separate memory.

b)

Structures and unions both have shared memory.

c)

Structures have separate memory; unions have shared memory.

d)

Structures and unions both have separate memory.

14.

Which operator is used to access structure members?

a)

The arrow operator (->) for normal variables and dot operator (.) for pointers.

b)

The dot operator (.) for normal variables and arrow operator (->) for pointers.

c)

The dot operator (.) for pointers and arrow operator (->) for normal variables.

d)

The arrow operator (->) for both normal variables and pointers.

15.

Define a pointer.

a)

A pointer is a variable that stores the value of another variable.

b)

A pointer is a variable that stores the address of another variable.

c)

A pointer is a variable that stores the type of another variable.

d)

A pointer is a variable that stores the size of another variable.

16.

How will you access value through a pointer?

a)

By using the address of the pointer variable.

b)

By using the value of the pointer variable.

c)

By using the dereference operator (*) on the pointer variable.

d)

By using the increment operator on the pointer variable.

17.

What is a null pointer?

a)

A pointer that points to a valid memory location.

b)

A pointer that points to the address of a variable.

c)

A pointer that does not point to any memory location (value is NULL).

d)

A pointer that points to the value of a variable.

18.

What does the operator * represent in pointers?

a)

It represents the address of the pointer.

b)

It represents the value of the pointer.

c)

It is the indirection/dereference operator used to access the value stored at the pointer’s address.

d)

It is the operator used to increment the pointer’s address.

19.

Discuss the void pointer with an example.

a)

A void pointer can store the address of any type of variable and has a specific data type.

b)

A void pointer cannot store the address of any type of variable.

c)

A void pointer can store the address of any type of variable and does not have any data type associated with it.

d)

A void pointer can only store the address of integer variables.

20.

What is an array of pointers?

a)

A collection of integers stored in an array

b)

A collection of memory addresses stored in an array

c)

A collection of strings stored in an array

d)

A collection of characters stored in an array

21.

What is a function pointer?

a)

A pointer to a variable

b)

A pointer to a function's return value

c)

A pointer variable that stores the address of a function

d)

A pointer to a memory location

22.

Which function returns the length of a string in C?

a)

strcpy()

b)

strcat()

c)

strlen()

d)

strcmp()

23.

What is recursion in programming?

a)

A function calling another function

b)

A function calling itself

c)

A loop within a function

d)

A function with no return value

24.

What is the factorial of 5 using the recursive function provided?

a)

120

b)

24

c)

60

d)

100

25.

What is an advantage of using the recursive function for calculating factorials?

a)

Simplifies code

b)

Reduces memory usage

c)

Increases speed

d)

Decreases complexity

26.

What is a disadvantage of using the recursive function for calculating factorials?

a)

More memory usage (stack)

b)

Slower execution

c)

Less accurate

d)

Harder to understand

27.

In call by value, what is passed to the function?

a)

A copy of the variable

b)

The address of the variable

c)

A reference to the variable

d)

The variable's type

28.

In call by reference, what is passed to the function?

a)

The address of the variable

b)

A copy of the variable

c)

The variable's type

d)

A constant value

29.

What does the gets() function do in C?

a)

Reads a string

b)

Prints a string with newline

c)

Reads an integer

d)

Prints an integer

30.

What does the puts() function do in C?

a)

Prints a string with newline

b)

Reads a string

c)

Prints an integer

d)

Reads an integer

31.

Classify the difference between structure and union.

a)

Structures can store different data types, unions cannot.

b)

Unions can store different data types, structures cannot.

c)

Structures allocate memory for all members, unions share memory.

d)

Unions allocate memory for all members, structures share memory.

32.

List the difference between user-defined function and built-in function.

a)

User-defined functions are pre-written, built-in functions are written by the user.

b)

Built-in functions are pre-written, user-defined functions are written by the user.

c)

Both are written by the user.

d)

Both are pre-written.

33.

Define argument. Differentiate formal and actual arguments.

a)

Formal arguments are used in function calls, actual arguments are used in function definitions.

b)

Actual arguments are used in function calls, formal arguments are used in function definitions.

c)

Both are used in function calls.

d)

Both are used in function definitions.

34.

Give the relation between the ‘&’ and ‘*’ in C pointers.

a)

‘&’ is used to access the value, ‘*’ is used to access the address.

b)

‘*’ is used to access the value, ‘&’ is used to access the address.

c)

Both are used to access the value.

d)

Both are used to access the address.

35.

When is a null pointer used?

a)

To point to a valid memory location.

b)

To indicate that a pointer does not point to any valid memory location.

c)

To point to the first element of an array.

d)

To point to the last element of an array.

36.

List the file operations in C paradigm.

a)

Open, Close, Read, Write, Append

b)

Start, Stop, Read, Write, Delete

c)

Open, Close, Start, Stop, Delete

d)

Read, Write, Start, Stop, Append

37.

How are arrays declared and initialized in C?

a)

int array[5] = {1, 2, 3, 4, 5};

b)

array int[5] = {1, 2, 3, 4, 5};

c)

int array = {1, 2, 3, 4, 5};

d)

array int = {1, 2, 3, 4, 5};

38.

Compare single-dimensional and two-dimensional arrays with examples.

a)

Single-dimensional: int array[5]; Two-dimensional: int array[5][5];

b)

Single-dimensional: int array[5][5]; Two-dimensional: int array[5];

c)

Both are declared as int array[5];

d)

Both are declared as int array[5][5];

39.

How will read and print a line of text using gets() and puts()?

a)

gets() reads a line, puts() prints a line.

b)

puts() reads a line, gets() prints a line.

c)

Both gets() and puts() read a line.

d)

Both gets() and puts() print a line.

40.

Exemplify the string function used to concatenate two strings in C.

a)

strcpy()

b)

strcat()

c)

strlen()

d)

strcmp()

41.

List out the advantage of using user-defined functions.

a)

They reduce code redundancy.

b)

They increase code redundancy.

c)

They make code harder to understand.

d)

They slow down program execution.

42.

What is the difference between actual and formal parameters?

a)

Actual parameters are used in function definitions, formal parameters are used in function calls.

b)

Formal parameters are used in function definitions, actual parameters are used in function calls.

c)

Both are used in function definitions.

d)

Both are used in function calls.

43.

Define a structure with an example.

a)

struct Student { int id; char name[50]; };

b)

struct Student { int id; char name; };

c)

struct Student { id; name[50]; };

d)

struct Student { int id; name[50]; };

44.

How will you access value through pointer?

a)

Using the ‘&’ operator.

b)

Using the ‘*’ operator.

c)

Using the ‘%’ operator.

d)

Using the ‘#’ operator.

45.

Exemplify an array of pointers.

a)

int *array[5];

b)

int array[5];

c)

int *array;

d)

int array;