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.

You are working on optimizing a simulation program that makes numerous calls to small functions. What technique can be used to potentially speed up the execution without significantly changing the logic of the program?

  • Inlining small functions
  • Converting the program to assembly code
  • Increasing the stack size
  • Using larger data types
Option A is the correct answer. Inlining small functions can potentially speed up the execution by reducing the overhead of function calls. It doesn't significantly change the logic of the program. Options B, C, and D are not the best approaches for optimizing the program.

An array of ________ can be used to call different functions based on an index.

  • Functions
  • Objects
  • Pointers
  • Structures
In C, you can use an array of function pointers to call different functions based on the index. Function pointers point to functions, making it possible to create arrays of functions and select them dynamically.

The function ______ is used in C to print a string to the standard output.

  • print()
  • puts()
  • display()
  • writeString()
The correct option is b) puts(). This function is used to print a string to the standard output, followed by a newline character.

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.