How do you declare a pointer variable in C?

  • Using the % operator
  • Using the & operator
  • Using the * operator
  • Using the -> operator
In C, you declare a pointer variable using the * operator. For example, int *ptr; declares a pointer to an integer.

You are working on a program that simulates a chessboard. How would you represent the chessboard using arrays?

  • 1D Array
  • 2D Array
  • Hash Table
  • Linked List
A chessboard is best represented using a 2D array because it provides a grid structure, allowing easy indexing for each square.

The ______ function in C can be used to change the position of the file pointer in a stream.

  • fmove()
  • fseek()
  • fileptr()
  • fposition()
The correct option is b) fseek(). This function is used to set the file position indicator for the specified stream, allowing you to move the file pointer to a specific location.

In a graphics rendering engine, you need to apply different transformations (e.g., rotate, scale, translate) to objects. How can function pointers be used to simplify the implementation?

  • Define a function pointer for each transformation type
  • Use if-else statements to select transformations
  • Use global variables to store transformation functions
  • Implement each transformation directly in the code
Option A is the correct answer. By defining a function pointer for each transformation type, you can easily switch between different transformations without altering the engine's core logic. Options B, C, and D are less flexible and efficient. Option A simplifies the code.

Using the ________ function, the file pointer can be moved to the end of a file.

  • fseek()
  • rewind()
  • ftell()
  • fsetpos()
The correct option is fseek(). This function is used to set the file position indicator to a specific position within the file. When the SEEK_END constant is provided as the reference point, it moves the file pointer to the end of the file, allowing operations like appending data.

Which function would you use to compare two strings lexicographically in C?

  • strcat()
  • strcmp()
  • strcpy()
  • strlen()
You would use the strcmp() function to compare two strings lexicographically in C. It returns 0 if the strings are equal, a positive value if the first string is greater, and a negative value if the second string is greater.

What is a potential drawback of using bit fields in a cross-platform application?

  • Inefficient memory usage
  • Lack of platform portability
  • Compiler-specific behavior
  • Slower execution
The correct option is c) Compiler-specific behavior. Using bit fields in a cross-platform application can lead to issues due to compiler-specific behavior. Different compilers may interpret bit fields differently, causing inconsistencies across platforms.

In C, a ________ is used to store a sequence of characters.

  • array
  • function
  • string
  • variable
In C, a 'string' is used to store a sequence of characters. A string is an array of characters, typically represented as an array of 'char' data type.

What is the advantage of using pointers to structures instead of directly using structures?

  • Easier debugging
  • Enhanced code readability
  • Faster access to data
  • Improved memory management
Using pointers to structures allows for improved memory management by reducing memory wastage. When a structure is passed as a function argument, it is copied, leading to extra memory usage. Pointers avoid this issue.

Which searching algorithm is typically the most straightforward to implement?

  • Binary search
  • Hash table
  • Jump search
  • Linear search
Linear search is the most straightforward searching algorithm as it involves a simple step-by-step comparison of elements in the array.

In C, what is the difference in memory allocation between character arrays and string literals?

  • Character arrays are automatically null-terminated, while string literals are not.
  • Character arrays are stored in read-write memory, while string literals are stored in read-only memory.
  • Character arrays cannot be used as function arguments, while string literals can.
  • String literals are stored in read-write memory, while character arrays are stored in read-only memory.
Character arrays in C are typically stored in read-write memory, allowing you to modify their contents. In contrast, string literals are stored in read-only memory, making them immutable. This difference in memory allocation is essential for understanding how to work with strings in C.

What is the default starting value of an enumeration in C?

  • 0
  • 1
  • The value of the first enumeration constant
  • Unspecified
In C, if no initial value is provided for the first enumeration constant, it starts with 0. Subsequent constants increment by 1.