In C, what is the result of the expression (5 & 3)?

  • 0
  • 1
  • 3
  • 5
In C, the '&' operator is the bitwise AND operator. When you perform (5 & 3), it bitwise ANDs the binary representation of 5 (0101) and 3 (0011). The result is 0001, which is 1 in decimal.

What is the behavior of malloc when the size requested is zero?

  • It goes into an infinite loop
  • It returns a null pointer (NULL)
  • It returns a pointer to a zero-sized memory block
  • It returns an error
When you request zero bytes of memory using malloc, it returns a null pointer (NULL) rather than allocating a zero-sized memory block. This is useful for special cases when you need a pointer that doesn't point to any memory.

How can double pointers be used in dynamic memory allocation in C?

  • To allocate multi-dimensional arrays
  • To create pointer arrays
  • To manage pointer arithmetic
  • To pass a pointer to a pointer
Double pointers are used in dynamic memory allocation when you need to pass a pointer to a pointer (to allocate and manage multi-dimensional arrays) or create arrays of pointers. They provide an extra level of indirection, which is beneficial for managing memory efficiently.

What is the time complexity of the linear search algorithm in the worst case?

  • O(1)
  • O(log n)
  • O(n)
  • O(n^2)
The linear search algorithm has a worst-case time complexity of O(n) because in the worst scenario, it needs to iterate through the entire array to find the target element.

In C programming, what is tail recursion?

  • A recursion that involves a loop
  • A recursion with a base case at the beginning
  • A recursion with a base case at the end
  • A recursion with no base case
Tail recursion in C is a type of recursion where the base case is located at the end of the recursive function. This means that the recursive call is the last operation in the function, making it more efficient and easier for the compiler to optimize.

Using a union can lead to efficient memory usage when you need to store different ________ at different times.

  • data types
  • members
  • structures
  • values
When you use a union, you can store different data types in the same memory location, depending on the specific member you access. This can help save memory when you need to handle various types of data at different times.

You are developing an application that needs to represent a value that could either be an integer or a floating-point number. How could you efficiently represent this data using C?

  • Using a linked list
  • Using a structure
  • Using a union
  • Using an array
In C, a union allows you to efficiently represent data that can be either an integer or a floating-point number, as it allows sharing the same memory location for different data types. Arrays, structures, and linked lists are not suitable for this purpose.

What is the primary purpose of using pointers in a C function?

  • To allocate memory dynamically
  • To execute loops
  • To perform arithmetic operations
  • To store character data
Pointers in C allow you to allocate memory dynamically. They are often used to work with data structures, dynamic memory allocation, and creating flexible functions.

Which function is used to close a file that has been opened using fopen?

  • fclose
  • fopen
  • fread
  • fwrite
The fclose function is used to close a file that has been opened using fopen. This is important to release system resources and ensure data is properly saved.

When would it be beneficial to use a function pointer instead of a direct function call?

  • Dynamically choosing a function to execute
  • Enhancing compile-time error checking
  • Reducing code complexity
  • Simplifying code structure
Using a function pointer is beneficial when you need to dynamically choose a function to execute at runtime. It offers flexibility and is useful in various scenarios.