wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Mastering C Programming Concepts

Total questions: 84

Worksheet time: 42mins

Name
Class
Date
1.

What is the correct syntax to include a header file in C?

a)

#include or #include "header.h"

b)

#header

c)

#include {header.h}

d)

import header.h

2.

Explain the difference between '==' and '=' in C.

a)

'==' is used to declare variables while '=' is for comparison.

b)

The difference is that '=' is for assignment and '==' is for comparison.

c)

Both '=' and '==' are used for assignment.

d)

'==' is for assignment and '=' is for comparison.

3.

What is a pointer in C and how is it declared?

a)

A pointer in C is a variable that stores the address of another variable. It is declared using the syntax 'type *pointerName;'. For example, 'int *ptr;'.

b)

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

c)

A pointer in C is a type of function that returns a variable.

d)

A pointer in C is declared using 'pointerName *type;'.

4.

How do you allocate memory dynamically in C?

a)

Use 'malloc', 'calloc', or 'realloc' functions.

b)

Use 'new' operator for memory allocation.

c)

Use 'free' to allocate memory.

d)

Use 'printf' to allocate memory.

5.

What is the purpose of the 'main' function in a C program?

a)

The 'main' function is where all the functions are declared.

b)

The 'main' function is used for defining global variables.

c)

The 'main' function is the entry point of a C program.

d)

The 'main' function handles memory allocation in a C program.

6.

Describe the use of 'printf' and 'scanf' functions.

a)

'printf' formats input data, while 'scanf' displays output.

b)

'printf' and 'scanf' are both used for file operations.

c)

'printf' is used for reading input, while 'scanf' outputs text.

d)

'printf' outputs formatted text, while 'scanf' reads formatted input.

7.

What are the different storage classes in C?

a)

dynamic

b)

auto, register, static, extern

c)

shared

d)

local

8.

How do you define a structure in C?

a)

StructName struct { dataType member1; dataType member2; };

b)

struct StructName { member1, member2; };

c)

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

d)

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

9.

What is the significance of the 'return' statement?

a)

The 'return' statement is used to declare a variable.

b)

The 'return' statement pauses the function's execution.

c)

The 'return' statement is only used in loops.

d)

The 'return' statement signifies the end of a function's execution and provides a value to the function caller.

10.

Explain the concept of recursion with an example.

a)

Recursion is a method where a function calls itself to solve smaller instances of the same problem.

b)

Recursion is a method where a function runs in parallel to solve problems.

c)

Recursion is a technique that involves using loops to repeat a function.

d)

Recursion is when a function is executed only once without any repetition.

11.

What is the difference between an array and a pointer?

a)

An array can change size dynamically, while a pointer cannot.

b)

A pointer is a collection of elements, while an array is a single memory address.

c)

An array holds a single value, while a pointer can hold multiple values.

d)

An array is a fixed-size collection of elements, while a pointer is a variable that holds the address of a memory location.

12.

How can you pass an array to a function in C?

a)

Arrays cannot be passed to functions in C; you must use pointers instead.

b)

You can pass an array to a function by using the syntax 'functionName(dataType arrayName[], int size)'.

c)

You can pass an array by using 'functionName(arrayName, size)' without specifying the data type.

d)

You can only pass arrays by copying their elements into individual parameters.

13.

What are the different types of loops available in C?

a)

loop until condition

b)

foreach loop

c)

for loop, while loop, do while loop

d)

repeat until loop

14.

What is a preprocessor directive in C?

a)

A preprocessor directive is a type of variable in C.

b)

A preprocessor directive is a function that executes at runtime.

c)

A preprocessor directive is a command that starts with '@' for error handling.

d)

A preprocessor directive in C is a command that begins with '#' and is used for tasks like including files or defining macros.

15.

How do you handle errors in C programming?

a)

Handle errors by checking return values, using errno, implementing error handling functions, and using setjmp/longjmp for critical errors.

b)

Ignore errors completely

c)

Use global variables to track errors

d)

Always print error messages to the console

16.

What is the purpose of the 'sizeof' operator in C?

a)

'sizeof' is a function that calculates the total memory used by a program.

b)

'sizeof' returns the size of a variable or data type in bytes.

c)

'sizeof' is used to allocate memory dynamically.

d)

'sizeof' is used to declare the size of an array.

17.

How do you create a multi-dimensional array in C?

a)

Use the syntax 'dataType arrayName[size1][size2];'.

b)

Declare it as 'dataType arrayName[size1, size2];'.

c)

Multi-dimensional arrays cannot be created in C.

d)

Use 'dataType arrayName[size1] = { {value1, value2}, {value3, value4} };'.

18.

What is the role of the 'break' statement in loops?

a)

'break' is used to exit a loop or switch statement prematurely.

b)

'break' pauses the execution of a loop for a specified time.

c)

'break' is used to skip the current iteration of a loop.

d)

'break' is used to continue the next iteration of a loop.

19.

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

a)

'const' is a storage class that defines the lifetime of a variable.

b)

'const' is used to define a variable that can be modified.

c)

'const' is used to declare a function that cannot return a value.

d)

'const' indicates that the value of a variable cannot be changed after initialization.

20.

How do you define a union in C?

a)

union UnionName { dataType member1; dataType member2; } = {value1, value2};

b)

UnionName union { dataType member1; dataType member2; };

c)

union { member1: dataType; member2: dataType; } UnionName;

d)

union UnionName { dataType member1; dataType member2; ... };

21.

What is the difference between 'malloc' and 'calloc' in C?

a)

'malloc' and 'calloc' are identical in functionality.

b)

'malloc' is used for allocating memory for arrays, while 'calloc' is for single variables.

c)

'malloc' allocates memory without initializing it, while 'calloc' allocates memory and initializes it to zero.

d)

'malloc' is used for dynamic memory allocation, while 'calloc' is for static memory allocation.

22.

What is the purpose of the 'static' storage class in C?

a)

'static' is used to declare global variables only.

b)

'static' is used to allocate memory dynamically.

c)

'static' makes a variable retain its value between function calls.

d)

'static' limits the visibility of a variable to the file it is declared in.

23.

How do you declare a function pointer in C?

a)

type (functionName)();

b)

type *functionName;

c)

type (*functionName)();

d)

functionName type();

24.

What is the significance of the 'volatile' keyword in C?

a)

'volatile' indicates that a variable may be changed unexpectedly, preventing the compiler from optimizing it.

b)

'volatile' is used to declare a variable that cannot be modified.

c)

'volatile' is a storage class that defines the lifetime of a variable.

d)

'volatile' is used to declare a function that cannot return a value.

25.

What is the purpose of the 'return' type in a function declaration in C?

a)

The 'return' type is only relevant for void functions.

b)

The 'return' type specifies the type of value the function will return.

c)

The 'return' type is used to declare global variables.

d)

The 'return' type indicates the function will not return any value.

26.

What is the significance of the 'break' statement in switch cases?

a)

'break' is used to exit the switch statement and prevent fall-through.

b)

'break' is used to pause the execution of the switch statement.

c)

'break' is not applicable in switch statements.

d)

'break' is used to skip the current case in a switch statement.

27.

How do you declare a constant variable in C?

a)

dataType variableName = const value;

b)

dataType const variableName;

c)

constant dataType variableName;

d)

const dataType variableName;

28.

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

a)

'enum' is used to define a set of named integer constants.

b)

'enum' is a function that returns a value based on conditions.

c)

'enum' is used to declare a variable that can hold multiple values.

d)

'enum' is a data type that allows for dynamic memory allocation.

29.

How do you declare a function pointer in C?

a)

pointerType pointerName = &functionName;

b)

dataType (*pointerName)(parameterTypes);

c)

dataType pointerName(parameterTypes);

d)

functionType pointerName = (dataType *)functionName;

30.

What is the role of the 'continue' statement in loops?

a)

'continue' skips the current iteration and proceeds to the next iteration of the loop.

b)

'continue' exits the loop entirely.

c)

'continue' is used to break out of nested loops.

d)

'continue' pauses the loop for a specified time.

31.

What is the purpose of the 'extern' storage class in C?

a)

'extern' is used to allocate memory dynamically.

b)

'extern' is used to declare a variable that is defined in another file.

c)

'extern' limits the visibility of a variable to the file it is declared in.

d)

'extern' is used to declare local variables only.

32.

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

a)

'const' indicates that a variable's value cannot be changed after initialization.

b)

'const' is used to declare a variable that can be modified.

c)

'const' is a storage class that defines the lifetime of a variable.

d)

'const' is used to declare a function that cannot return a value.

33.

How do you define a union in C?

a)

union UnionName { member1, member2; };

b)

UnionName union { dataType member1; dataType member2; };

c)

union { member1: dataType; member2: dataType; } UnionName;

d)

union UnionName { dataType member1; dataType member2; ... };

34.

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

a)

'typedef' is used to define a new data type from scratch.

b)

'typedef' is used to declare a function that cannot return a value.

c)

'typedef' is used to create an alias for an existing data type.

d)

'typedef' is a storage class that limits variable visibility.

35.

What does the '&&' operator do in C?

a)

'&&' is a logical AND operator that returns true if both operands are true.

b)

'&&' is a bitwise AND operator.

c)

'&&' is used to concatenate two strings.

d)

'&&' is a comparison operator that checks for equality.

36.

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

a)

'volatile' is a storage class that defines the lifetime of a variable.

b)

'volatile' is used to declare a variable that cannot be modified.

c)

'volatile' indicates that a variable may be changed unexpectedly, preventing the compiler from optimizing it.

d)

'volatile' is used to declare a function that cannot return a value.

37.

What is the purpose of the 'sizeof' operator in C?

a)

'sizeof' is used to declare the size of a structure.

b)

'sizeof' returns the size of a variable in bytes.

c)

'sizeof' is used to allocate memory dynamically.

d)

'sizeof' is a function that counts the number of elements in an array.

38.

What is the difference between 'struct' and 'union' in C?

a)

'struct' is used for function declarations, while 'union' is for variable declarations.

b)

'struct' is a type of pointer, while 'union' is a type of array.

c)

'struct' allocates memory for all members, while 'union' shares memory among its members.

d)

'struct' can only hold integers, while 'union' can hold any data type.

39.

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

a)

'extern' is used to define a variable with local scope.

b)

'extern' is used to declare a variable that is defined in another file.

c)

'extern' is used to declare a function that cannot return a value.

d)

'extern' is a storage class that limits variable visibility to the function it is declared in.

40.

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

a)

'static' is a storage class that defines the lifetime of a variable only within a function.

b)

'static' restricts the visibility of a variable to the file it is declared in.

c)

'static' allows a variable to retain its value between function calls.

d)

'static' is used to declare a variable that can be modified.

41.

What is the function of the 'sizeof' operator when applied to an array?

a)

'sizeof' returns the size of the first element in the array.

b)

'sizeof' cannot be used with arrays.

c)

'sizeof' returns the number of elements in the array.

d)

'sizeof' returns the total size of the array in bytes.

42.

How do you create a pointer to a structure in C?

a)

pointerName = new StructName();

b)

struct *pointerName = &StructName;

c)

pointerName struct StructName;

d)

StructName *pointerName;

43.

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

a)

'volatile' is used to declare a function that cannot return a value.

b)

'volatile' is used to declare a variable that can be modified by external factors, preventing compiler optimizations.

c)

'volatile' indicates that a variable's value can change at any time, such as in multi-threaded applications.

d)

'volatile' is a storage class that limits the visibility of a variable to the file it is declared in.

44.

How do you dynamically allocate memory for an array in C?

a)

Use 'arrayName = new dataType[size];'.

b)

Use the syntax 'arrayName = malloc(size * sizeof(dataType));'.

c)

Dynamic memory allocation is not possible for arrays in C.

d)

Use 'arrayName = allocate(size);'.

45.

What is the difference between 'malloc' and 'calloc' in C?

a)

'malloc' allocates memory without initializing it, while 'calloc' allocates memory and initializes it to zero.

b)

'malloc' is used for allocating memory for structures, while 'calloc' is for arrays.

c)

'malloc' requires the size of each element, while 'calloc' requires the total size.

d)

There is no difference; both functions serve the same purpose.

46.

What is the purpose of the 'break' statement in loops?

a)

'break' is used to pause the loop for a specified time.

b)

'break' skips the current iteration and continues with the next one.

c)

'break' exits the loop immediately.

d)

'break' is used to terminate the program.

47.

What does the '||' operator do in C?

a)

'||' is a logical OR operator that returns true if at least one operand is true.

b)

'||' is a bitwise OR operator.

c)

'||' is used to concatenate two strings.

d)

'||' is a comparison operator that checks for inequality.

48.

What is the significance of the 'sizeof' operator in relation to pointers?

a)

'sizeof' returns the size of the pointer type, not the size of the data it points to.

b)

'sizeof' cannot be used with pointers.

c)

'sizeof' returns the size of the data type pointed to by the pointer.

d)

'sizeof' is used to allocate memory for pointers.

49.

What is the purpose of the 'static' storage class in C?

a)

'static' is used for dynamic memory allocation.

b)

'static' limits the visibility of a variable to the file it is declared in.

c)

'static' is only applicable to global variables.

d)

'static' is used to declare variables that retain their value between function calls.

50.

How do you create a pointer to a structure in C?

a)

struct StructName *pointerName;

b)

struct *pointerName = StructName;

c)

pointerName struct StructName;

d)

struct StructName pointerName*;

51.

What is the role of the 'continue' statement in loops?

a)

'continue' is used to break out of nested loops.

b)

'continue' pauses the loop for a specified time.

c)

'continue' exits the loop entirely.

d)

'continue' skips the current iteration and proceeds to the next iteration of the loop.

52.

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

a)

'typedef' is a function that returns a new data type.

b)

'typedef' is used to create an alias for an existing data type.

c)

'typedef' is used to define a variable's scope.

d)

'typedef' is a storage class that limits variable visibility.

53.

What is the role of the 'continue' statement in loops?

a)

'continue' skips the current iteration and proceeds to the next iteration of the loop.

b)

'continue' is used to terminate the program.

c)

'continue' exits the loop immediately.

d)

'continue' pauses the loop for a specified time.

54.

What is the purpose of the 'volatile' keyword in relation to multi-threading in C?

a)

'volatile' is used to declare a function that cannot return a value.

b)

'volatile' is a storage class that defines the lifetime of a variable.

c)

'volatile' ensures that a variable is always read from memory, preventing compiler optimizations that could lead to stale data.

d)

'volatile' is used to declare a variable that cannot be modified.

55.

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

a)

'typedef' is a storage class that defines the lifetime of a variable.

b)

'typedef' is used to declare global variables.

c)

'typedef' is a function that returns a new data type.

d)

'typedef' is used to create an alias for existing data types.

56.

What is the difference between '++i' and 'i++' in C?

a)

'++i' is used for floating-point numbers, while 'i++' is for integers.

b)

'++i' and 'i++' are identical in functionality.

c)

'++i' increments the value before it is used, while 'i++' increments it after.

d)

'++i' is a preprocessor directive, while 'i++' is a function.

57.

What is the purpose of the 'switch' statement in C?

a)

The 'switch' statement is used for looping through arrays.

b)

The 'switch' statement is used to execute a block of code based on a specific condition.

c)

The 'switch' statement is a way to declare multiple variables at once.

d)

The 'switch' statement is used to handle exceptions in C.

58.

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

a)

'typedef' is used to define new functions.

b)

'typedef' is used to create an alias for existing data types.

c)

'typedef' is used to declare global variables only.

d)

'typedef' is a storage class that limits variable visibility.

59.

What is the difference between '++i' and 'i++' in C?

a)

'++i' increments the value before it is used, while 'i++' increments it after.

b)

'++i' and 'i++' are identical in functionality.

c)

'++i' is used for floating-point numbers, while 'i++' is for integers.

d)

'++i' is a preprocessor directive, while 'i++' is a function.

60.

How do you define a macro in C using the '#define' directive?

a)

macro define MACRO_NAME(value);

b)

#define MACRO_NAME value

c)

define MACRO_NAME(value)

d)

macro MACRO_NAME = value;

61.

What is the purpose of the 'extern' storage class in C?

a)

'extern' is a storage class that defines the lifetime of a variable only within a function.

b)

'extern' is used to allocate memory dynamically.

c)

'extern' is used to declare a variable that is defined in another file.

d)

'extern' restricts the visibility of a variable to the file it is declared in.

62.

How do you define a structure in C?

a)

struct StructName { dataType member1; dataType member2; };

b)

structure StructName { member1, member2; };

c)

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

d)

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

63.

What is the purpose of the 'sizeof' operator in C?

a)

'sizeof' cannot be used with arrays.

b)

'sizeof' is used to allocate memory for variables.

c)

'sizeof' returns the number of elements in an array.

d)

'sizeof' returns the size of a variable or data type in bytes.

64.

How do you free dynamically allocated memory in C?

a)

Use 'delete arrayName;'.

b)

Use 'dispose(arrayName);'.

c)

Use 'free(arrayName);'.

d)

Memory cannot be freed in C.

65.

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

a)

'volatile' indicates that a variable may be changed unexpectedly.

b)

'volatile' is used to declare a variable that cannot be modified.

c)

'volatile' is a storage class that limits variable visibility.

d)

'volatile' is used to optimize memory allocation.

66.

How do you declare a function pointer in C?

a)

dataType *pointerName(parameterTypes);

b)

pointerName dataType(parameterTypes);

c)

dataType pointerName(parameterTypes);

d)

dataType (*pointerName)(parameterTypes);

67.

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

a)

'volatile' tells the compiler that a variable may be changed unexpectedly.

b)

'volatile' is used to declare a variable that cannot be modified.

c)

'volatile' is used to optimize memory usage.

d)

'volatile' is a storage class that limits variable visibility.

68.

What is the difference between 'struct' and 'union' in C?

a)

There is no difference; both serve the same purpose.

b)

'struct' can only contain primitive data types, while 'union' can contain any data type.

c)

'struct' is used for dynamic memory allocation, while 'union' is not.

d)

'struct' allocates memory for all members, while 'union' shares memory among its members.

69.

How do you declare a multi-dimensional array of pointers in C?

a)

dataType *arrayName[size1];

b)

dataType arrayName[size1][size2];

c)

dataType *arrayName[size1][size2];

d)

dataType **arrayName;

70.

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

a)

'enum' is used to declare a variable that can hold multiple data types.

b)

'enum' is a function that returns the size of an array.

c)

'enum' is a data type that allows for dynamic memory allocation.

d)

'enum' is used to define a set of named integer constants.

71.

What is the difference between 'struct' and 'union' in C?

a)

'struct' is used for dynamic memory allocation, while 'union' is for static memory allocation.

b)

'struct' allocates memory for all members, while 'union' shares memory among its members.

c)

'struct' is a type of function, while 'union' is a variable type.

d)

'struct' can only hold integers, while 'union' can hold any data type.

72.

How do you define a macro in C using the '#define' directive?

a)

#define MACRO_NAME value

b)

macro MACRO_NAME = value;

c)

macro = #define MACRO_NAME value;

d)

define MACRO_NAME(value)

73.

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

a)

'const' is used to define a constant function.

b)

'const' is used to declare a variable whose value cannot be changed after initialization.

c)

'const' is used to declare a variable that can be modified by external factors.

d)

'const' is a storage class that limits the visibility of a variable.

74.

How do you handle errors in C using 'errno'?

a)

'errno' is used to allocate memory dynamically.

b)

Check the value of 'errno' after a function call to determine if an error occurred.

c)

'errno' is a function that returns the last error code.

d)

'errno' is set to zero by default and indicates no error.

75.

What is the difference between 'malloc' and 'calloc' in C?

a)

'malloc' is faster than 'calloc' because it does not initialize memory.

b)

'malloc' and 'calloc' are identical in functionality.

c)

'malloc' is used for allocating memory for arrays, while 'calloc' is for single variables.

d)

'malloc' allocates memory without initializing it, while 'calloc' allocates memory and initializes it to zero.

76.

What is the purpose of the 'extern' storage class in C?

a)

'extern' is used to allocate memory dynamically.

b)

'extern' is a storage class that limits the visibility of a variable to the file it is declared in.

c)

'extern' is used to define a variable that cannot be modified.

d)

'extern' is used to declare a variable that is defined in another file.

77.

How do you create a multi-dimensional array in C?

a)

Use the syntax 'dataType arrayName[size1][size2];'.

b)

Multi-dimensional arrays are not supported in C.

c)

Declare multiple arrays of the same type to simulate a multi-dimensional array.

d)

Use the syntax 'dataType arrayName[size1, size2];'.

78.

What is the purpose of the 'goto' statement in C?

a)

'goto' is used to jump to a specific label in the code.

b)

'goto' is used to exit a loop.

c)

'goto' is a function that executes a block of code.

d)

'goto' is used to define a variable scope.

79.

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

a)

'typedef' is a storage class that limits variable visibility.

b)

'typedef' is used to define new data types only.

c)

'typedef' is used to create an alias for existing data types.

d)

'typedef' is used to declare functions in C.

80.

What is the difference between 'struct' and 'union' in C?

a)

There is no difference; both serve the same purpose.

b)

'struct' allocates memory for all members, while 'union' allocates memory for the largest member only.

c)

'struct' is used for dynamic memory allocation, while 'union' is for static memory allocation.

d)

'struct' can only contain primitive data types, while 'union' can contain any data type.

81.

How do you declare a constant variable in C?

a)

constant dataType variableName;

b)

dataType variableName = constantValue;

c)

const dataType variableName;

d)

dataType const variableName;

82.

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

a)

'static' limits the visibility of a variable to the file it is declared in.

b)

'static' indicates that a variable retains its value between function calls.

c)

'static' is used to declare a variable that cannot be modified.

d)

'static' is a storage class that defines the lifetime of a variable only within a function.

83.

What is the difference between 'malloc' and 'calloc' in C?

a)

'malloc' allocates memory without initializing it, while 'calloc' allocates memory and initializes it to zero.

b)

'malloc' is used for allocating memory for arrays, while 'calloc' is for single variables.

c)

'malloc' requires the size in bytes, while 'calloc' requires the number of elements and size of each element.

d)

'malloc' can only allocate memory for integers, while 'calloc' can allocate for any data type.

84.

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

a)

'typedef' is used to create an alias for an existing data type.

b)

'typedef' is used to define a new data type from scratch.

c)

'typedef' is used to declare a function that cannot return a value.

d)

'typedef' is a storage class that limits the visibility of a variable.