You are tasked with writing a C function to calculate the factorial of a number. Which programming technique would be most suitable for this task?

  • Iteration
  • Object-Oriented Programming
  • Parallel Programming
  • Recursion
Iteration is the most suitable technique for calculating the factorial of a number. It avoids the risk of stack overflow associated with recursion and is more efficient for this specific task.

In a program that processes large volumes of numerical data, which file format would be more efficient in terms of storage space and data retrieval speed?

  • Binary File Format
  • CSV (Comma-Separated Values)
  • JSON (JavaScript Object Notation)
  • XML (eXtensible Markup Language)
Binary File Format would be more efficient for large volumes of numerical data. Unlike plain text formats like CSV, binary formats store data in a more compact and direct way, reducing storage space requirements. Additionally, binary files allow for faster data retrieval because they can be read directly into memory without parsing, making them suitable for applications that prioritize speed and efficiency in processing numerical data.

What is the primary use of the fseek function in file handling?

  • Closing a file
  • Moving the cursor to the end of a file
  • Moving the file cursor to a specific position
  • Setting the file's permissions
The primary use of the fseek() function is to move the file cursor to a specific position within the file. This allows you to read or write data at a specific location in the file.

How is data stored in a two-dimensional array in memory?

  • In reverse order
  • Randomly, without any order
  • Sequentially, row by row
  • Vertically, column by column
In a two-dimensional array, data is stored sequentially, row by row. Each row is contiguous in memory, and elements are stored in the order they appear in the row.

What is the default value of elements in an array declared as int arr[5]; in C?

  • 0
  • 5
  • Random integers
  • Undefined
In C, when you declare an array without initializing it, all its elements are set to 0 by default. Hence, the correct answer is 0.

The function ________ is used in C to allocate memory for an array of specified size dynamically.

  • free
  • malloc
  • printf
  • scanf
In C, the function 'malloc' is used to allocate memory for an array of specified size dynamically. 'malloc' stands for memory allocation.

The function ________ can be used to determine the size of a file in C.

  • size()
  • filesize()
  • file_size()
  • fsize()
The correct option is fsize(). The fsize() function is commonly used in C to determine the size of a file by positioning the file pointer at the end and then retrieving the position.

String literals in C are stored in ________ memory segment.

  • Code
  • Data
  • Heap
  • Stack
In C, string literals are stored in the data memory segment. This segment contains constants, such as global and static variables.

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.

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 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.

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.