wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

C Programming Challenge for Students

Total questions: 16

Worksheet time: 8mins

Name
Class
Date
1.

What is a pointer in C?

a)

A pointer is a variable that stores a string in C.

b)

A pointer is a special kind of loop in C.

c)

A pointer is a type of function in C.

d)

A pointer is a variable that holds the address of another variable in C.

2.

How do you declare a pointer variable?

a)

int *ptr;

b)

*int ptr;

c)

pointer int ptr;

d)

int ptr;

3.

What is the purpose of the 'malloc' function?

a)

To create a new thread in a program.

b)

To initialize variables to zero.

c)

To allocate memory dynamically.

d)

To free up memory after use.

4.

How do you free dynamically allocated memory?

a)

Use 'free(pointer)' for malloc/calloc/realloc and 'delete pointer' for new.

b)

Use 'dispose(pointer)' for malloc/calloc/realloc

c)

Invoke 'clear(pointer)' to free memory

d)

Call 'remove(pointer)' for new allocations

5.

What is the difference between 'fopen' and 'fclose'?

a)

'fopen' opens a file; 'fclose' closes a file.

b)

'fopen' opens a directory; 'fclose' opens a file.

c)

'fopen' deletes a file; 'fclose' creates a file.

d)

'fopen' reads a file; 'fclose' writes to a file.

6.

How do you read data from a file in C?

a)

Use read() to directly access the file contents.

b)

Use file_get_contents() to read the entire file at once.

c)

Use fopen() to open the file, then read with fscanf() or fgets(), and close with fclose().

d)

Open the file with open() and read using readlines().

7.

What is a structure in C?

a)

A structure in C is a way to define constants.

b)

A structure in C is a function that performs calculations.

c)

A structure in C is a user-defined data type that groups different data types together.

d)

A structure in C is a built-in data type for integers.

8.

How do you define a structure in C?

a)

struct { member1: dataType; member2: dataType; };

b)

struct StructName { dataType member1; dataType member2; dataType member3; };

c)

struct StructName { member1, member2; };

d)

struct StructName { dataType member1; dataType member2; ... };

9.

What is dynamic memory allocation?

a)

Dynamic memory allocation allows programs to allocate memory during execution, adapting to varying data needs.

b)

Dynamic memory allocation refers to the fixed allocation of memory for data structures.

c)

Dynamic memory allocation is the process of allocating memory at compile time.

d)

Dynamic memory allocation is a method to free up all memory used by a program at once.

10.

How do you allocate memory for an array using 'malloc'?

a)

int *array = (int *)malloc(n * sizeof(int));

b)

int array[n];

c)

int *array = (int *)malloc(sizeof(int));

d)

int *array = malloc(n);

11.

What is the purpose of the 'sizeof' operator?

a)

To determine the size of a data type or object in bytes.

b)

To find the maximum value of a data type.

c)

To convert data types between different formats.

d)

To calculate the memory allocation for a variable.

12.

How do you write data to a file in C?

a)

Call fwrite() without opening a file first.

b)

Use scanf() to read data from a file.

c)

Use fclose() before writing any data.

d)

Use fopen() to open a file, fprintf() or fwrite() to write data, and fclose() to close the file.

13.

What is a linked list?

a)

A linked list is a static data structure that cannot change size.

b)

A linked list is a linear data structure where each element points to the next, forming a chain.

c)

A linked list is a collection of unordered elements.

d)

A linked list is a type of tree structure.

14.

How do you create a linked list in C?

a)

Use an array to store the elements directly.

b)

Create a class for the linked list instead of a struct.

c)

Implement linked list using only pointers without a struct.

d)

Define a struct for the node, e.g., 'struct Node { int data; struct Node* next; };'.

15.

What is the difference between stack and heap memory?

a)

Stack memory is for dynamic allocation and is slower.

b)

Stack memory can grow indefinitely while heap memory is fixed.

c)

Stack memory is for static allocation and is faster; heap memory is for dynamic allocation and is more flexible.

d)

Heap memory is for static allocation and is less flexible.

16.

How do you access the value of a pointer?

a)

Use the '*' operator to dereference the pointer.

b)

Use the '->' operator to get the value of the pointer.

c)

Access the pointer value directly without dereferencing.

d)

Use the '&' operator to access the pointer.