module 1
module 2
module 3
module 4
module 5
100

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

  • A) It is where the program starts execution.
  • B) It defines global variables.
  • C) It is used to declare other functions.
  • D) It is used to allocate memory.

A) It is where the program starts execution.

100

Which header file is required to use the printf() and scanf() functions in C?

  • A) stdlib.h
  • B) stdio.h
  • C) conio.h
  • D) string.h

B) stdio.h

100

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

  • A) ++i increments the value before using it, while i++ increments the value after using it.
  • B) Both perform the same operation.
  • C) ++i is faster than i++.
  • D) i++ is used for pointers, and ++i is used for integers.

A) ++i increments the value before using it, while i++ increments the value after using it.

100

What is a pointer in C?

  • A) A variable that stores the address of another variable.
  • B) A function that returns the address of a variable.
  • C) A special type of array.
  • D) A keyword in C.

A) A variable that stores the address of another variable.

100

What is the use of the return statement in a function?

  • A) To exit from the function and optionally return a value to the calling function.
  • B) To declare a variable inside a function.
  • C) To allocate memory dynamically.
  • D) To define a constant value.

A) To exit from the function and optionally return a value to the calling function.

200

What is the purpose of the volatile keyword in C, and when should it be used?

  • A) It is used to declare a variable that can be modified in a signal handler or interrupt service routine.
  • B) It is used to prevent the compiler from optimizing the variable, ensuring that the value is always read from memory.
  • C) It is used to create a constant variable.
  • D) It is used to declare a pointer that cannot be modified.

B) It is used to prevent the compiler from optimizing the variable, ensuring that the value is always read from memory.

200

What is the difference between malloc() and calloc() in C?

  • A) malloc() allocates memory without initializing it, while calloc() allocates and initializes the memory to zero.
  • B) malloc() allocates memory for a single variable, while calloc() allocates memory for an array.
  • C) malloc() returns a pointer to the allocated memory, while calloc() returns a pointer to an integer.
  • D) There is no difference; they are synonyms.

A) malloc() allocates memory without initializing it, while calloc() allocates and initializes the memory to zero.

200

What is the purpose of the extern keyword in C?

  • A) It is used to declare a global variable or function that is defined in another file.
  • B) It is used to declare a variable that cannot be modified.
  • C) It is used to declare a variable within a block scope.
  • D) It is used to declare a function prototype.

A) It is used to declare a global variable or function that is defined in another file.

200

How does the sizeof() operator work with arrays and pointers?

  • A) For an array, it returns the total number of bytes of the array; for a pointer, it returns the size of the pointer type.
  • B) For both arrays and pointers, it returns the number of elements.
  • C) It returns the size of the first element for arrays and the total size for pointers.
  • D) It returns the size of the data type, not the actual memory size allocated.

A) For an array, it returns the total number of bytes of the array; for a pointer, it returns the size of the pointer type.

200

What is a union in C, and how does it differ from a structure?

  • A) A union allows storing different data types in the same memory location, while a structure allocates separate memory for each member.
  • B) A union can only store one data type at a time, while a structure can store multiple data types simultaneously.
  • C) A union is smaller in size compared to a structure.
  • D) A union cannot be nested, while a structure can.

A) A union allows storing different data types in the same memory location, while a structure allocates separate memory for each member.

M
e
n
u