The typedef keyword can be used to simplify the declaration of ________ in C.

  • Data structures
  • Functions
  • Macros
  • Variables
The typedef keyword in C is commonly used to simplify the declaration of user-defined data structures, making it easier to work with complex data types.

The function ________ can be unsafe to use as it does not check for buffer overflow while reading a string in C.

  • fgets
  • getchar
  • gets
  • scanf
The correct answer is fgets. gets is unsafe due to buffer overflow issues, scanf can be problematic when not used carefully, and getchar is used for character input, not strings. fgets is a safer choice for reading strings.

The keyword ________ is used to declare a variable that retains its value between successive calls to the functions in which it is declared.

  • auto
  • extern
  • register
  • static
In C, the static keyword is used to declare a variable that retains its value between successive calls to the functions in which it is declared. This keyword is used to create a local variable with a persistent value, maintaining its state across function calls.

What is a potential consequence of not freeing dynamically allocated memory in a long-running C program?

  • Buffer overflow
  • Memory leaks
  • Null pointer dereference
  • Stack overflow
When dynamically allocated memory isn't freed, it leads to memory leaks. This means that the memory remains allocated and cannot be reclaimed for other purposes, which can result in a program consuming more and more memory over time.

In C++, function overloading allows multiple functions to have the same name but with different ________.

  • parameters
  • return types
  • function names
  • access specifiers
The correct answer is return types. In C++, function overloading is when you have multiple functions with the same name but differing in their parameter types or the number of parameters. However, their return types must be different to distinguish them. The other options are not relevant to function overloading.

What happens to the memory allocation when you define variables inside a union?

  • Variables are allocated separate memory locations
  • Variables are automatically allocated on the heap
  • Variables are stored in a separate file
  • Variables share the same memory location
Variables defined inside a union share the same memory location, so only one variable's value is stored at any given time. Changing the value of one variable affects others in the union.

What is the purpose of using inline functions in C?

  • Enable recursive functions
  • Improve code maintainability
  • Increase code size
  • Reduce function call overhead
Inline functions in C reduce the overhead of function calls, as the code is inserted directly in place of the function call. This can improve performance.

The typedef keyword in C is used to create an ________ for existing data types.

  • Alias
  • Enumeration
  • Function
  • Pointer
In C, the typedef keyword is used to create an alias for existing data types, making code more readable and maintainable by providing descriptive names.

What is the relationship between the addresses of consecutive elements in a one-dimensional array?

  • Addresses are assigned based on the element's value
  • Addresses are the same for all elements
  • Consecutive elements have addresses in random order
  • Consecutive elements have consecutive addresses
In a one-dimensional array, consecutive elements have consecutive addresses. The address of each element is one unit (e.g., byte) greater than the previous element.

The keyword ________ is used in C to define a constant.

  • constant
  • define
  • identifier
  • value
In C, the keyword 'const' is used to define a constant. It is used to declare variables as constant, and their values cannot be changed after declaration.