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.

The function ________ is used to move the file pointer to a specific position in the file.

  • file_seek()
  • fseek()
  • move_pointer()
  • position_file()
In file handling, fseek() is employed to move the file pointer to a specified position within the file. This is crucial for navigating and accessing specific parts of a file during read or write operations.

You're developing a program to calculate the area of a circle. What data type would be most suitable to store the radius, considering it can be a fractional value?

  • char
  • double
  • float
  • int
To store the radius of a circle with fractional values, the most suitable data type in C is 'double' as it offers high precision for such calculations.

What is the purpose of using random access in file handling?

  • To access files in a random order.
  • To create files with random names.
  • To generate random numbers for file operations.
  • To perform direct read/write operations at any position within the file.
The purpose of using random access in file handling is to perform direct read and write operations at any position within the file. Random access allows you to jump to a specific location in a file and read or write data without having to sequentially process the entire file. It's especially useful for large files or databases.

You are working on a software project in C++ that requires sorting a list of items in multiple ways. How could you leverage function overloading to achieve this?

  • Define multiple functions with the same name but different parameters for each sorting method.
  • Implement a single function with the most generic sorting algorithm to handle all sorting needs.
  • Use inline functions for sorting, allowing for multiple sorting methods within one function.
  • Utilize global variables to store sorting methods for easy access and reuse.
Function overloading in C++ allows you to define multiple functions with the same name but different parameters, enabling the use of various sorting methods for different data types.

How do you declare a pointer to an integer in C?

  • int ptr;
  • int* ptr;
  • int_pointer ptr;
  • pointer(int) p;
To declare a pointer to an integer in C, you use the format int* ptr;. This declares a pointer variable named ptr that can store the address of an integer.

How does the 'register' keyword affect the storage of a variable in a C program?

  • It's allocated in a CPU register
  • It's allocated in the data segment
  • It's allocated in the heap
  • It's allocated in the stack
The 'register' keyword suggests to the compiler to store the variable in a CPU register, which can lead to faster access. However, it's just a hint, and the compiler may choose to ignore it.

You are tasked with optimizing a C program that manipulates large strings. What standard library functions might be critical to review for potential performance bottlenecks?

  • getchar() and putchar()
  • malloc() and free()
  • printf() and scanf()
  • strlen() and strcat()
When optimizing a C program that manipulates large strings, functions like strlen() and strcat() should be reviewed for potential performance bottlenecks as they involve string manipulation and can be resource-intensive.