The keyword ________ is used to declare a variable that retains its value between successive calls to the functions in which it is declared.

  • auto
  • extern
  • register
  • static
In C, the static keyword is used to declare a variable that retains its value between successive calls to the functions in which it is declared. This keyword is used to create a local variable with a persistent value, maintaining its state across function calls.

In a program that processes images, each pixel is represented by three values corresponding to the Red, Green, and Blue (RGB) intensities. What would be an efficient way to represent a pixel in C?

  • An efficient way to represent a pixel in C is by using a struct with three integer fields.
  • An efficient way to represent a pixel in C is by using a single integer value.
  • An efficient way to represent a pixel in C is by using three separate variables.
  • An efficient way to represent a pixel in C is by using a character array.
The correct option is 1. Using a struct with three integer fields is the most efficient way to represent a pixel in C because it encapsulates the RGB values as a single unit, making it easy to work with. The other options would be less efficient and less organized.

You are working on a program that needs to perform different actions based on the day of the week. Which control statement would be most appropriate to use?

  • for
  • if-else
  • switch
  • while
The correct answer is B) switch. The switch statement is ideal for situations where you want to execute different code blocks based on the value of a variable (in this case, the day of the week).

What is the purpose of the fopen function in C?

  • Closes a file
  • Opens a file for both reading and writing
  • Opens a file for reading
  • Opens a file for writing
The fopen function in C is used to open a file for reading. It returns a file pointer that can be used to read data from the file.

Which function is used to display output on the console in C?

  • display()
  • print()
  • printf()
  • write()
In C, the 'printf()' function is used to display output on the console.

Which mode should be used with fopen to open a file for both reading and writing?

  • "a+"
  • "r+"
  • "rb+"
  • "w+"
To open a file for both reading and writing in C, you should use the "r+" mode with the fopen function. This mode allows you to perform both read and write operations on the file.

How can you redirect error messages in a C program to a file instead of displaying them on the console?

  • freopen()
  • perror()
  • stderr
  • stdout
The freopen() function in C is used to redirect standard streams, such as stderr, to a specified file, enabling error messages to be stored in a file instead of the console.

The ________ of a function includes the function's name, return type, and the types of its parameters.

  • Declaration
  • Definition
  • Implementation
  • Prototype
The prototype of a function includes the function's name, return type, and the types of its parameters. It provides a declaration of the function's signature, allowing the compiler to check function calls for correctness.

Why is it recommended to use pointer arithmetic instead of array indexing for traversal in some cases?

  • It ensures type safety and prevents buffer overflows
  • It provides faster traversal and better optimization
  • It reduces the risk of pointer errors
  • It simplifies code and makes it more readable
Using pointer arithmetic for traversal is recommended in some cases because it can result in faster traversal and better optimization, especially in complex data structures. However, it requires careful handling to avoid pointer errors.

You're working on a C program that needs to manipulate and process data about a list of products in a store. Each product has several attributes like name, price, and quantity. What approach would you take to store and process this data efficiently?

  • 2D Array
  • Array of Structures
  • Singly Linked List
  • Vector
An array of structures would be an efficient approach for storing and processing data about products in a store. This data structure allows you to create a custom data type that contains all the attributes of each product (name, price, quantity), making it easy to manage and process product information efficiently.