WorksheetsQuiz on Arrays in Programming
Total questions: 45
Worksheet time: 23mins
What is an array in programming?
A collection of similar data items stored under a common name
A single data item stored in a variable
A function that performs operations on data
A type of loop used in programming
How are uninitialized elements in an array handled in C?
They are set to one
They are automatically initialized to zero
They are left undefined
They are initialized to null
What is the difference between single-dimensional and two-dimensional arrays?
Single-dimensional arrays store data in rows and columns
Two-dimensional arrays store data in a linear sequence
Single-dimensional arrays store data in a linear sequence
Two-dimensional arrays store data in a single line
How can you declare an array in C?
data_type array_name[size];
array_name[size] data_type;
data_type[size] array_name;
array_name data_type[size];
Which of the following is a method to initialize a string in C?
Using a loop
Using a string literal
Using a pointer
Using a function
What are two functions in the C string library?
printf(), scanf()
strlen(), strcpy()
malloc(), free()
fopen(), fclose()
Exemplify the string function used to concatenate two strings in C.
strcpy
strcat
strcmp
strlen
Define a function. Write syntax for function declaration and call.
A function is a block of statements that performs a specific task. Syntax: int add(int x, int y);
A function is a variable that stores data. Syntax: int add = 5;
A function is a loop that iterates over a block of code. Syntax: for(int i=0; i<10; i++);
A function is a conditional statement. Syntax: if(x > y)
What is the difference between actual and formal parameters?
Actual parameters are used in function definition; formal parameters are used in function call.
Actual parameters are stored in the called function; formal parameters are stored in the calling function.
Actual parameters are stored in the calling function; formal parameters are stored in the called function.
Actual parameters are variables; formal parameters are constants.
List out the advantage of using user-defined functions.
Increase the source code
Difficult to maintain and modify
Reduce the source code
Cannot be called from anywhere in the program
List out the categories of functions.
Functions with arguments and no return values
Functions with no arguments and no return values
Functions with arguments and with return values
All of the above
Define a structure with an example.
A structure is a single variable of one data type. Example: int number;
A structure is a collection of variables of different data types. Example: struct student { char name[20]; int ID; }
A structure is a loop that iterates over a block of code. Example: for(int i=0; i<10; i++);
A structure is a conditional statement. Example: if(x > y)
Differentiate between structures and unions with an example.
Structures have shared memory; unions have separate memory.
Structures and unions both have shared memory.
Structures have separate memory; unions have shared memory.
Structures and unions both have separate memory.
Which operator is used to access structure members?
The arrow operator (->) for normal variables and dot operator (.) for pointers.
The dot operator (.) for normal variables and arrow operator (->) for pointers.
The dot operator (.) for pointers and arrow operator (->) for normal variables.
The arrow operator (->) for both normal variables and pointers.
Define a pointer.
A pointer is a variable that stores the value of another variable.
A pointer is a variable that stores the address of another variable.
A pointer is a variable that stores the type of another variable.
A pointer is a variable that stores the size of another variable.
How will you access value through a pointer?
By using the address of the pointer variable.
By using the value of the pointer variable.
By using the dereference operator (*) on the pointer variable.
By using the increment operator on the pointer variable.
What is a null pointer?
A pointer that points to a valid memory location.
A pointer that points to the address of a variable.
A pointer that does not point to any memory location (value is NULL).
A pointer that points to the value of a variable.
What does the operator * represent in pointers?
It represents the address of the pointer.
It represents the value of the pointer.
It is the indirection/dereference operator used to access the value stored at the pointer’s address.
It is the operator used to increment the pointer’s address.
Discuss the void pointer with an example.
A void pointer can store the address of any type of variable and has a specific data type.
A void pointer cannot store the address of any type of variable.
A void pointer can store the address of any type of variable and does not have any data type associated with it.
A void pointer can only store the address of integer variables.
What is an array of pointers?
A collection of integers stored in an array
A collection of memory addresses stored in an array
A collection of strings stored in an array
A collection of characters stored in an array
What is a function pointer?
A pointer to a variable
A pointer to a function's return value
A pointer variable that stores the address of a function
A pointer to a memory location
Which function returns the length of a string in C?
strcpy()
strcat()
strlen()
strcmp()
What is recursion in programming?
A function calling another function
A function calling itself
A loop within a function
A function with no return value
What is the factorial of 5 using the recursive function provided?
120
24
60
100
What is an advantage of using the recursive function for calculating factorials?
Simplifies code
Reduces memory usage
Increases speed
Decreases complexity
What is a disadvantage of using the recursive function for calculating factorials?
More memory usage (stack)
Slower execution
Less accurate
Harder to understand
In call by value, what is passed to the function?
A copy of the variable
The address of the variable
A reference to the variable
The variable's type
In call by reference, what is passed to the function?
The address of the variable
A copy of the variable
The variable's type
A constant value
What does the gets() function do in C?
Reads a string
Prints a string with newline
Reads an integer
Prints an integer
What does the puts() function do in C?
Prints a string with newline
Reads a string
Prints an integer
Reads an integer
Classify the difference between structure and union.
Structures can store different data types, unions cannot.
Unions can store different data types, structures cannot.
Structures allocate memory for all members, unions share memory.
Unions allocate memory for all members, structures share memory.
List the difference between user-defined function and built-in function.
User-defined functions are pre-written, built-in functions are written by the user.
Built-in functions are pre-written, user-defined functions are written by the user.
Both are written by the user.
Both are pre-written.
Define argument. Differentiate formal and actual arguments.
Formal arguments are used in function calls, actual arguments are used in function definitions.
Actual arguments are used in function calls, formal arguments are used in function definitions.
Both are used in function calls.
Both are used in function definitions.
Give the relation between the ‘&’ and ‘*’ in C pointers.
‘&’ is used to access the value, ‘*’ is used to access the address.
‘*’ is used to access the value, ‘&’ is used to access the address.
Both are used to access the value.
Both are used to access the address.
When is a null pointer used?
To point to a valid memory location.
To indicate that a pointer does not point to any valid memory location.
To point to the first element of an array.
To point to the last element of an array.
List the file operations in C paradigm.
Open, Close, Read, Write, Append
Start, Stop, Read, Write, Delete
Open, Close, Start, Stop, Delete
Read, Write, Start, Stop, Append
How are arrays declared and initialized in C?
int array[5] = {1, 2, 3, 4, 5};
array int[5] = {1, 2, 3, 4, 5};
int array = {1, 2, 3, 4, 5};
array int = {1, 2, 3, 4, 5};
Compare single-dimensional and two-dimensional arrays with examples.
Single-dimensional: int array[5]; Two-dimensional: int array[5][5];
Single-dimensional: int array[5][5]; Two-dimensional: int array[5];
Both are declared as int array[5];
Both are declared as int array[5][5];
How will read and print a line of text using gets() and puts()?
gets() reads a line, puts() prints a line.
puts() reads a line, gets() prints a line.
Both gets() and puts() read a line.
Both gets() and puts() print a line.
Exemplify the string function used to concatenate two strings in C.
strcpy()
strcat()
strlen()
strcmp()
List out the advantage of using user-defined functions.
They reduce code redundancy.
They increase code redundancy.
They make code harder to understand.
They slow down program execution.
What is the difference between actual and formal parameters?
Actual parameters are used in function definitions, formal parameters are used in function calls.
Formal parameters are used in function definitions, actual parameters are used in function calls.
Both are used in function definitions.
Both are used in function calls.
Define a structure with an example.
struct Student { int id; char name[50]; };
struct Student { int id; char name; };
struct Student { id; name[50]; };
struct Student { int id; name[50]; };
How will you access value through pointer?
Using the ‘&’ operator.
Using the ‘*’ operator.
Using the ‘%’ operator.
Using the ‘#’ operator.
Exemplify an array of pointers.
int *array[5];
int array[5];
int *array;
int array;
