Command line arguments are accessed in a C program using the parameters ________ and ________ in the main function.
- argc, argv
- input, output
- param1, param2
- source, target
The correct answer is (a) argc, argv. In C, the main function can take two parameters: argc, which represents the number of command-line arguments, and argv, which is an array of strings containing those arguments.
What is the main difference between function declaration and function definition in C?
- Declarations contain the function's code
- Declarations specify the function's name
- Definitions declare the function's return type
- Definitions provide the function's implementation
The main difference between function declaration and function definition in C is that declarations specify the function's name and data types, while definitions provide the actual implementation of the function.
When defining a bit field, what does the number after the colon represent?
- Bit order
- Bit position
- Bit size
- Bit value
The number after the colon represents the bit size, indicating how many bits the bit field can occupy.
A two-dimensional array can be visualized as a ________.
- Linked List
- One-dimensional array
- Table
- Tree Structure
A two-dimensional array can be visualized as a table with rows and columns.
In C++, what happens when two overloaded functions have the same number and types of parameters but differ in return type?
- It's a compilation error
- It's undefined behavior
- The function with the least specific return type is called
- The function with the most specific return type is called
When two overloaded functions in C++ have the same number and types of parameters but differ in return type, it results in a compilation error. C++ uses the function's signature, including the return type, to differentiate between overloaded functions. If two functions have the same parameters and differ only in return type, it becomes ambiguous, and the compiler cannot determine which function to call.
In what scenario would using an array of structures be more beneficial than using multiple arrays?
- When data access patterns are unpredictable
- When dealing with unrelated data
- When each element has multiple attributes
- When memory efficiency is not a concern
Using an array of structures is advantageous when dealing with related data that share the same attributes or fields, making it more organized and efficient compared to multiple arrays.
You're writing a C program that needs to read from a file and display the content on the screen. How would you handle the situation if the file does not exist?
- Create an empty file
- Ignore and continue
- Print an error message and exit
- Prompt user for a new file name
Printing an error message and exiting the program is a common approach when a required file is not found. It informs the user about the issue and halts the program execution to prevent further errors.
When reading a text file in C, which function can be used to read data from the file?
- fgets
- fputs
- fread
- fwrite
When reading a text file in C, the fgets function is commonly used to read data from the file. It reads one line of text at a time, making it suitable for text file processing.
You are tasked with creating a system to manage a library's book inventory. How can structures be utilized in this scenario?
- To define the layout of the library building
- To manage software licenses
- To organize and store information about each book
- To represent information about library patrons
In this scenario, structures can be used to organize and store information about each book in the library. Each structure can hold data like the book's title, author, publication date, and available copies, making it an efficient way to manage the library's inventory.
The ________ loop guarantees at least one execution of the loop body, even if the condition is false from the start.
- do-while
- for
- switch
- while
The 'do-while' loop in programming ensures that the loop body is executed at least once, even if the condition is false initially. It's used when you want to run the loop body before checking the condition.