What is the effect of not specifying the size of the array when initializing it with a list of values?

  • Compilation error
  • The array is initialized with a default size of 10
  • The array size is automatically set based on the number of values
  • Undefined behavior
When initializing an array with a list of values in C without specifying the size, the array size is automatically set based on the number of values. It is a convenient feature in C known as array initialization without a size specification.

The function ________ is used to read formatted input from the standard input.

  • print
  • scanf
  • printf
  • cout
The "scanf" function is used in C and C++ to read formatted input from the standard input (usually the keyboard). It allows you to input and store values in variables while specifying the format in which data should be entered. Options like "print," "printf," and "cout" are used for output, not input.

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 a common use case for having an array of structures?

  • Storing data in a linked list.
  • Storing data with different structures.
  • Storing multiple records of the same type.
  • Storing unrelated data types together.
A common use case for having an array of structures is to store multiple records of the same type. This allows you to create collections of related data with the same structure, such as a list of students' information or employee records.

What is the purpose of using pointers to structures in C programming?

  • To access structure members
  • To create a new structure
  • To declare a structure
  • To store an integer
Pointers to structures are used to access and manipulate individual members of a structure.

Which looping construct is best suited when the number of iterations is known beforehand?

  • do-while
  • for
  • switch
  • while
The 'for' loop is commonly used when the number of iterations is known beforehand, as it allows you to specify the initialization, condition, and iteration steps in a compact manner.

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

  • allocate
  • define
  • struct
  • typedef
In C, the "struct" keyword is used to define a structure. Structures are used to group related data members under a single name.