You are working on an application that requires fast data retrieval times. What method of file access would be most suitable?
- Direct File Access
- Indexed File Access
- Random Access
- Sequential File Access
For fast data retrieval times, Random Access is the most suitable method. Unlike Sequential File Access, which reads data sequentially, and Indexed File Access, which uses an index to locate data, Random Access allows direct access to any part of the file. This is crucial for applications where quick retrieval of specific data is essential, such as databases and real-time systems.
You are developing a contact management system where each contact can have multiple addresses (home, work, etc.). How can you efficiently represent this information using structures?
- By creating a separate database for addresses
- By using an array for each contact
- By using separate variables for each address
- By utilizing a structure to hold multiple addresses within a contact structure
To efficiently represent multiple addresses for each contact, you can use a structure to hold multiple addresses within a contact structure. This approach ensures that each contact can have different types of addresses, such as home and work, making it a practical way to manage contact information.
How can you determine if you have reached the end of a file while reading it in C?
- Check if the file size is zero.
- Count the number of lines in the file.
- Examine the file's creation date.
- Use the feof function to check for end-of-file status.
You can determine if you've reached the end of a file in C by using the feof function, which checks for the end-of-file status of the stream.
What is the scope of a local variable defined inside a function in C?
- Global scope
- Limited to the block
- Limited to the function
- No scope
In C, a local variable defined inside a function has scope limited to that specific function. It cannot be accessed from outside the function.
In a C++ application, you notice that a function is being called with different types of arguments, but there is only one function definition. What feature of C++ could be allowing this behavior?
- Dynamic casting
- Function overloading
- Inheritance and polymorphism
- Operator overloading
The behavior of calling a function with different argument types using a single function definition is achieved through function overloading in C++. This feature allows multiple function definitions with the same name but different parameter types.
You are working on a program that processes user input, and you want to ensure that the input string does not exceed a certain length to prevent buffer overflow. Which string handling function would be appropriate to use?
- strcpy
- strncat
- strncpy
- strstr
To limit the length of user input and prevent buffer overflow, the strncpy function is appropriate. It allows you to copy a specified number of characters from the input to the destination, ensuring the destination buffer does not overflow. strstr searches for a substring, strncat concatenates strings with a specified limit, and strcpy copies a string without length control.
The ________ algorithm is known for its simplicity but is inefficient for sorting large datasets.
- Bubble Sort
- Merge Sort
- Quick Sort
- Selection Sort
The correct option is 'Bubble Sort'. While Bubble Sort is easy to understand, it is not efficient for large datasets due to its O(n^2) time complexity.
An enumeration is a user-defined data type that consists of integral ________.
- Characters
- Functions
- Pointers
- Values
An enumeration is a user-defined data type that consists of integral values, typically used for defining a set of named integer constants.
When opening a file with fopen, what happens if the file does not exist and the mode is set to 'r'?
- It appends data to the existing file.
- It creates a new file.
- It overwrites the file's content.
- It returns a NULL pointer.
When opening a file with fopen in read mode ('r') and the file doesn't exist, it returns a NULL pointer, indicating that the file was not successfully opened.
When passing an array to a function in C, what is actually being passed?
- A pointer to the first element
- The entire array
- The size of the array
- The value of the first element in the array
In C, when passing an array to a function, only a pointer to the first element is passed, allowing the function to access the entire array.