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.

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.

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.

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.

You're debugging a segmentation fault in a program and find that a pointer is being accessed after it has been freed. What is this type of pointer error called?

  • Dangling pointer error
  • Invalid pointer error
  • Null pointer error
  • Out-of-scope pointer error
This type of pointer error is called a "dangling pointer error." It occurs when a pointer is accessed after it has been freed or deallocated, leading to undefined behavior and segmentation faults.

What is a potential risk when using the strcpy function in C?

  • Buffer overflow
  • Compilation error
  • Memory leak
  • Segmentation fault
The strcpy function in C copies a string to a destination buffer without checking the length, which can lead to buffer overflow if the source string is longer than the destination buffer. This can result in overwriting adjacent memory, causing potential security vulnerabilities or program crashes.

When a floating-point number is declared using the ________ keyword, it allows for more precision than a regular float.

  • double
  • float
  • long double
  • precision
When a floating-point number is declared using the 'long double' keyword in C, it allows for more precision than a regular 'float' or 'double'.

You're developing a text editor and need to implement a search feature. Which function could be useful to check if a certain word exists in a text?

  • strcat
  • strlen
  • strrev
  • strstr
In this scenario, the strstr function is appropriate for searching for a specific word within a text. It returns a pointer to the first occurrence of the specified word in the text, allowing you to check if it exists. strrev reverses a string, strlen provides the length of a string, and strcat concatenates strings.

In a software program managing a university's data, you need to store information about students and their enrolled courses. How can nested structures be used in this context?

  • To create graphics for the university's website
  • To manage student financial records
  • To represent complex data relationships between students and their courses
  • To send emails to students
Nested structures can be used to represent complex data relationships. In this context, they can be used to create a structure for students that contains another structure for their enrolled courses. This allows for efficient storage and retrieval of information about students and their courses.

In C programming, a function that calls itself and the recursive call is the last operation before it returns is known as ________ recursion.

  • Direct
  • Indirect
  • Non-tail
  • Tail
In C programming, a function that calls itself and the recursive call is the last operation before it returns is known as "Tail" recursion. Tail recursion is an efficient form of recursion as it allows the compiler to optimize the function calls and avoid unnecessary overhead.

What is the impact on memory usage when using pointers to structures?

  • It always increases memory usage
  • It always reduces memory usage
  • It depends on how pointers are used
  • It has no impact on memory usage
The impact on memory usage when using pointers to structures depends on how the pointers are used. When used wisely, pointers can reduce memory usage because they allow for more efficient data manipulation without creating redundant copies. However, improper use can lead to memory leaks or increased memory usage. It's important to manage memory properly when working with pointers to structures.

What is the role of pointers in relation to structures in C?

  • Pointers allow dynamic allocation of structures
  • Pointers can only be used within structures
  • Pointers can't be used with structures
  • Structures cannot have pointers
Pointers in C can be used to dynamically allocate memory for structures, which is essential for creating flexible data structures and managing memory efficiently.