In C, a function pointer can be used to call a function without knowing its ________ at compile time.

  • Function name
  • Memory location
  • Parameters
  • Return type
Function pointers in C allow you to call a function by its name dynamically, making it possible to call functions without knowing their names at compile time.

What is the impact of using inline functions on the size of the compiled binary?

  • Decreases binary size
  • Depends on compiler optimization
  • Increases binary size
  • No impact on binary size
Inline Functions are a feature in C/C++ that help reduce function call overhead. They can lead to smaller binary sizes due to inlining, where the function's code is inserted directly at the call site, reducing the need for a separate function call.

To resize a previously allocated memory block, the function ________ is used in C.

  • calloc()
  • free()
  • malloc()
  • realloc()
To resize a previously allocated memory block in C, the function realloc() is used. It allows you to change the size of the memory block while preserving the existing data. malloc() and calloc() are used for initial memory allocation, and free() deallocates memory.

How can function pointers be used to implement callbacks in C?

  • Function pointers are not used for callbacks
  • Function pointers are used for dynamic linking
  • Function pointers are used to implement recursion
  • Function pointers can be used to pass a function as an argument to another function
Function pointers in C can be used to implement callbacks. By passing a function pointer as an argument to another function, you can dynamically specify the function to be called, enabling flexibility in callback implementations.

When a value is passed to a function by value, what is passed to the function?

  • A copy of the value
  • A pointer to the value
  • A reference to the value
  • The memory address of the value
When a value is passed to a function by value, a copy of the actual value is passed to the function. Changes made to the parameter inside the function do not affect the original value.

An array declared as int arr[10]; allocates memory for ________ integers.

  • 10
  • 15
  • 20
  • 5
When you declare an array like int arr[10], it allocates memory for 10 integers.

What is the primary purpose of structures in C programming?

  • Allocate memory for arrays
  • Create loops in C
  • Define functions
  • Group variables of different data types
In C programming, structures are used to group variables of different data types into a single unit. They allow you to create a composite data type, which is useful for organizing related information. This helps in better organization and management of data in your program.

What potential issue should be considered when using recursion in C programs?

  • Compiler error
  • Inefficient use of CPU
  • Memory leak
  • Stack overflow error
When using recursion in C, one potential issue to consider is a stack overflow error. Recursion can lead to a rapidly growing stack, which may exhaust the available memory and cause a program to crash.

You need to create a program that dynamically allocates memory for an array and allows the user to specify the size of the array at runtime. What concept in C would be crucial to achieve this?

  • Arrays
  • Functions
  • Pointers
  • Structures
The concept crucial to dynamically allocate memory for an array and allow the user to specify the size at runtime is "Pointers." Pointers are used to manage memory dynamically in C. Structures, Arrays, and Functions are not directly related to this task.

How can a dangling pointer issue be avoided after freeing memory in C?

  • Call free() twice
  • Increase the pointer value after freeing
  • Set the pointer to NULL after freeing
  • Use a double pointer
To avoid a dangling pointer issue, it's a good practice to set the pointer to NULL after freeing the memory it points to. This way, the pointer won't accidentally be accessed, preventing potential issues.