You are developing a large-scale simulation that runs for a long duration. After running for a few hours, you notice the program slows down significantly. What could be a likely reason for this behavior?
- CPU Overheating
- Memory Leak
- Network Latency
- Software Bug
A memory leak is a common reason for slowing down a long-running program. It occurs when memory is allocated but not released, leading to resource exhaustion and slow performance.
When an array of strings is declared in C, what is it essentially an array of?
- Characters
- Floats
- Integers
- Pointers
When an array of strings is declared in C, it is essentially an array of pointers to character arrays (strings). Each element of the array is a pointer to a character array.
In C, a structure is a user-defined data type that allows grouping of variables of ________ data types.
- Different
- Similar
- Undefined
- Unrelated
In C, structures allow grouping of variables of similar data types. They are used to create composite data types for organizing related variables.
What is the purpose of the feof function in file handling in C?
- It checks if the file pointer is at the beginning.
- It checks if the end-of-file indicator is set.
- It returns the size of the file.
- It verifies if the file is open for editing.
The correct option is It checks if the end-of-file indicator is set. The feof function is used to determine if the end-of-file indicator has been set for a stream, helping to identify whether the end of the file has been reached during file operations in C.
What is the behavior of a union when different data types of different sizes are used?
- It leads to a runtime error
- It results in a compilation error
- The union will have the size of the largest data type
- The union will have the size of the smallest data type
In C, when different data types of different sizes are used in a union, the union will have the size of the largest data type. This allows you to store data of different types in the same memory location.
In C, to ensure that there are no errors while writing to a file, you should check the return value of the ________ function.
- fclose
- ferror
- feof
- fflush
To ensure error-free file writing, you should check the return value of the ferror function, making option b) "ferror" the correct choice.
A structure containing an instance of another structure within it is known as a ________ structure.
- Arrayed
- Complex
- Inherited
- Nested
When a structure contains an instance of another structure within it, it is referred to as a nested structure.
A ________ pointer is a pointer that still points to a memory location that has been deallocated.
- Dangling
- Dynamic
- Null
- Static
A "dangling" pointer is a pointer that continues to reference a memory location that has been deallocated. This can lead to unexpected behavior and should be avoided.
What type of variable is one that is declared outside any function and is available throughout the program?
- Constant variable
- Global variable
- Local variable
- Static variable
A global variable is declared outside any function and is accessible throughout the program, making it available for all functions to use.
What is the main limitation of using typedef to create an alias for a data type?
- It adds flexibility to data types
- It can lead to confusion with multiple typedefs
- It enforces strong data typing
- It increases code readability
The main limitation of using typedef to create an alias is that it can lead to confusion when multiple typedefs are used for the same base type.
What is the primary disadvantage of using dynamic memory allocation for arrays in C?
- Fragmentation
- Inefficiency
- Limited Size
- Slow Access
Dynamic Memory Allocation can lead to memory fragmentation, which can waste memory and affect program performance.
What is a key advantage of using a sorted array over an unsorted array?
- Easier insertion of elements
- Faster searching
- Lower memory usage
- Random access
A key advantage of a sorted array is faster searching using techniques like binary search, which has a logarithmic time complexity.