In a two-dimensional array declared as int arr[5][10];, the expression arr[i][j] refers to the ________ element in memory.
- i-th column, j-th row
- i-th row, j-th column
- j-th column, i-th row
- j-th row, i-th column
In a two-dimensional array, the first index corresponds to rows, and the second index corresponds to columns. So, arr[i][j] refers to the element at the i-th row and j-th column.
What is the difference between stderr and stdout in the context of buffering?
- stderr is unbuffered, while stdout is line-buffered by default.
- stderr is line-buffered, while stdout is unbuffered.
- stderr is fully buffered, while stdout is line-buffered.
- stderr is fully buffered, while stdout is unbuffered.
The correct option is "stderr is unbuffered, while stdout is line-buffered by default." stderr is typically unbuffered, meaning that data is immediately written to the output, while stdout is line-buffered, meaning that it is buffered until a newline character is encountered.
You are working on a program that processes large datasets. Why might you choose to use pointers and pointer arithmetic to traverse the data?
- To enable dynamic data structures
- To enhance data access speed
- To improve memory efficiency
- To simplify code readability
Using pointers and pointer arithmetic can significantly improve data access speed. It allows direct memory access, reducing the need for complex data structures and enhancing performance in large dataset processing.
Which keyword is used in C to create an alias for a data type?
- enum
- struct
- typedef
- union
In C programming, the "typedef" keyword is used to create an alias or a new name for an existing data type. This makes the code more readable and can help in achieving better code organization.
The preprocessor directive ________ is used to include libraries in a C program.
- #define
- #ifdef
- #include
- #pragma
The correct answer is (b) #include. In C, the #include preprocessor directive is used to include libraries or header files. This allows you to use functions and definitions from those libraries in your program.
The ________ directive can be used in C to include a file only once in a program.
- #ifdef
- #ifndef
- #include
- #pragma
In C programming, the #include directive is used to include files in a program. When you want to include a file only once, you can use preprocessor directives like #ifndef and #define to create include guards.
Which function in C is used to flush the output buffer of a stream?
- clear()
- fflush()
- flush()
- flushout()
The correct function is fflush(). It is used to flush the output buffer of a stream, ensuring that any buffered data is written to the file or output device. This is particularly useful when you want to ensure that data is immediately written without waiting for the buffer to fill up.
How can you open a file for both reading and writing in C?
- fopen("file.txt", "rw")
- fopen("file.txt", "r+")
- fopen("file.txt", "w+")
- open("file.txt", "rw")
The correct option is b. fopen("file.txt", "r+"). This combination of mode flags in the fopen() function allows a file to be opened for both reading and writing, providing flexibility in file manipulation operations.
In a large software project, certain code needs to be compiled only for debugging purposes. How can preprocessor directives be used to achieve this?
- By using 'ifdef' and 'ifndef'
- By using 'for' loops
- By using 'switch' statements
- By using 'while' loops
Preprocessor directives like 'ifdef' and 'ifndef' can conditionally include or exclude sections of code based on predefined conditions. This is often used to include debugging code only during debugging builds. Options b, c, and d are not related to preprocessor directives.
You're developing a function that modifies an array of integers. To ensure that the original array is not altered, how should the array be passed to the function?
- Pass a copy of the array
- Pass a pointer to the array
- Pass by reference
- Pass by value
To ensure that the original array is not altered, you should pass a pointer to the array to the function. This way, the function can work with the original data without making a copy of the array. Pass by reference typically involves languages like C++ and is not a direct concept in C. Pass by value would create a copy of the array, which is not the desired behavior. Passing a copy of the array would have the same effect as passing by value.