What is the effect of not specifying the size of the array when initializing it with a list of values?
- Compilation error
- The array is initialized with a default size of 10
- The array size is automatically set based on the number of values
- Undefined behavior
When initializing an array with a list of values in C without specifying the size, the array size is automatically set based on the number of values. It is a convenient feature in C known as array initialization without a size specification.
The function ________ is used to read formatted input from the standard input.
- scanf
- printf
- cout
The "scanf" function is used in C and C++ to read formatted input from the standard input (usually the keyboard). It allows you to input and store values in variables while specifying the format in which data should be entered. Options like "print," "printf," and "cout" are used for output, not input.
String literals in C are stored in ________ memory segment.
- Code
- Data
- Heap
- Stack
In C, string literals are stored in the data memory segment. This segment contains constants, such as global and static variables.
The function ________ can be used to determine the size of a file in C.
- size()
- filesize()
- file_size()
- fsize()
The correct option is fsize(). The fsize() function is commonly used in C to determine the size of a file by positioning the file pointer at the end and then retrieving the position.
The function ________ is used in C to allocate memory for an array of specified size dynamically.
- free
- malloc
- printf
- scanf
In C, the function 'malloc' is used to allocate memory for an array of specified size dynamically. 'malloc' stands for memory allocation.
What is the default value of elements in an array declared as int arr[5]; in C?
- 0
- 5
- Random integers
- Undefined
In C, when you declare an array without initializing it, all its elements are set to 0 by default. Hence, the correct answer is 0.
How is data stored in a two-dimensional array in memory?
- In reverse order
- Randomly, without any order
- Sequentially, row by row
- Vertically, column by column
In a two-dimensional array, data is stored sequentially, row by row. Each row is contiguous in memory, and elements are stored in the order they appear in the row.
What is the primary use of the fseek function in file handling?
- Closing a file
- Moving the cursor to the end of a file
- Moving the file cursor to a specific position
- Setting the file's permissions
The primary use of the fseek() function is to move the file cursor to a specific position within the file. This allows you to read or write data at a specific location in the file.
In a program that processes large volumes of numerical data, which file format would be more efficient in terms of storage space and data retrieval speed?
- Binary File Format
- CSV (Comma-Separated Values)
- JSON (JavaScript Object Notation)
- XML (eXtensible Markup Language)
Binary File Format would be more efficient for large volumes of numerical data. Unlike plain text formats like CSV, binary formats store data in a more compact and direct way, reducing storage space requirements. Additionally, binary files allow for faster data retrieval because they can be read directly into memory without parsing, making them suitable for applications that prioritize speed and efficiency in processing numerical data.
You are tasked with writing a C function to calculate the factorial of a number. Which programming technique would be most suitable for this task?
- Iteration
- Object-Oriented Programming
- Parallel Programming
- Recursion
Iteration is the most suitable technique for calculating the factorial of a number. It avoids the risk of stack overflow associated with recursion and is more efficient for this specific task.