What function is commonly used in C for taking user input?
- gets
- printf
- puts
- scanf
The 'scanf' function is commonly used in C for taking user input. It allows you to read input values from the user and store them in variables.
You're developing a database system and need to frequently update records. What file handling technique would you use to efficiently update specific records without reading the entire file?
- Direct File Updating
- Indexed File Updating
- Random File Updating
- Sequential File Updating
Indexed File Updating would be the most efficient technique for frequently updating specific records in a database system. With an index, the system can quickly locate and update the desired record without the need to read the entire file sequentially. This reduces the time and resources required for updates, making it a suitable choice for scenarios where frequent record updates are a common operation in a database.
In the context of searching algorithms, why might a binary search be preferred over a linear search?
- Binary search guarantees to find the target quickly
- Binary search is always faster
- Binary search requires sorted data
- Binary search works for unsorted data
Binary search is preferred when data is sorted as it allows for efficient searching, while a linear search works for unsorted data.
Why might a programmer choose to use an array of structures in a C program?
- To create global variables
- To perform text formatting
- To sort data
- To store related data efficiently
Programmers use arrays of structures to efficiently manage and organize related data.
In the context of file handling, what is the advantage of using binary files over text files?
- Data preservation
- Human readability
- Portability
- Smaller file size
One of the advantages of using binary files over text files in file handling is data preservation. Binary files store data as a sequence of bytes, preserving the exact representation of data without any character encoding or formatting. This makes them suitable for storing complex data structures and preserving data integrity.
Which of the following best describes the concept of recursion in C programming?
- A function calling itself directly or indirectly
- A loop mechanism for repeating a set of instructions
- A method to divide a problem into smaller subproblems
- A way to define constant values
Recursion in C programming involves a function calling itself either directly or indirectly. It's a technique used to solve problems by breaking them down into smaller instances, making it an essential concept in programming.
How does using pointers with arrays affect the performance of a C program?
- It always degrades performance
- It can improve performance in some cases
- It has no effect on performance
- It only affects memory usage, not performance
Using pointers with arrays in a C program can actually improve performance in some cases. By using pointers, you can manipulate array elements more efficiently and access them directly, reducing the overhead of array indexing. This can lead to better performance. However, it's essential to use pointers carefully to avoid issues like memory corruption.
When writing data to a text file, which function is used to ensure that the data is written correctly?
- fprintf
- fputc
- fputs
- fwrite
The fprintf function is used to write formatted data to a text file in C. It allows you to specify the format and data to be written, ensuring that the data is written correctly with appropriate formatting.
The ________ sorting algorithm repeatedly steps through the list, compares adjacent elements and swaps them if they are in the wrong order.
- Binary
- Bubble
- Merge
- Quick
The 'Bubble' sorting algorithm repeatedly steps through the list, comparing adjacent elements, and swapping them if they are in the wrong order. It is a simple sorting algorithm but not very efficient for large datasets.
A ________ occurs when a program continues to use a pointer after it has been freed.
- Buffer Overflow
- Dangling Pointer
- Memory Leak
- Segmentation Fault
A Dangling Pointer occurs when a program continues to use a pointer after it has been freed. This can lead to undefined behavior, crashes, or data corruption. It's crucial to avoid using pointers that point to memory that has been deallocated.