WorksheetsArrays and Pointers in C
Total questions: 15
Worksheet time: 20mins
What is the syntax for declaring an array in C?
array_name = [array_size];
array_name = data_type[array_size];
array_name[array_size] = data_type;
data_type array_name[array_size];
What is the syntax for declaring a pointer in C?
int ptr;
ptr = int;
int *ptr();
int *ptr;
How is pointer arithmetic performed in C?
By dividing the pointer by an integer value
By multiplying the pointer with an integer value
By adding or subtracting an integer value to/from a pointer
By performing bitwise operations on the pointer
What is the difference between array and pointer in C?
Arrays are a fixed-size collection of elements, while pointers are variables that store memory addresses.
Arrays cannot be passed as arguments to functions, while pointers can
Arrays can only store integers, while pointers can store any data type
Arrays and pointers are the same thing
Explain the concept of passing an array to a function in C.
Passing an array to a function in C only allows access to the first element of the array
Passing an array to a function in C allows the function to work with the elements of the array.
Passing an array to a function in C is not possible
Passing an array to a function in C allows the function to modify the size of the array
How can you dynamically allocate memory for an array using pointers in C?
Use the 'realloc' function
Use the 'malloc' function
Use the 'free' function
Use the 'calloc' function
What is the purpose of the 'const' keyword in C?
To declare a constant variable that cannot be modified
To declare a variable that can only be modified within a specific function
To declare a variable that can be modified by any function
To declare a variable that can be modified by any other variable
Explain the concept of dynamic memory allocation in C.
Dynamic memory allocation in C allows the program to allocate memory at compile time
Dynamic memory allocation in C allows the program to allocate memory at runtime
Dynamic memory allocation in C is not possible
Dynamic memory allocation in C allows the program to allocate memory for global variables only
What is the purpose of the 'static' keyword in C?
To declare a variable that can be accessed only within the same function
To declare a variable that retains its value between function calls
To declare a variable that can be modified by any other variable
To declare a variable that can only be modified within a specific function
What is the syntax for declaring a multi-dimensional array in C?
data_type array_name[array_size1][array_size2];
array_name = data_type[array_size1][array_size2];
array_name = [array_size1][array_size2];
data_type[array_size1][array_size2] array_name;
Write the array declaration syntax for the items below
name: a
values: 2,1,3,5,4
Write the array declaration syntax for the items below (dynamic array declaration)
name: b
values: 0,2,4,6,8
Write the array declaration syntax for the items below (use realloc)
name: b
values: 0,2,4,6,8, 1, 3, 5, 7, 9
void minMaxAve (int *, int, int)
Given the prototype above, write the appropriate function header.
void minMaxAve (int *, int, int)
Given the prototype above, write the appropriate function call.
