The ________ directive is used to define symbolic names or constants in a C program.
- #constant
- #define
- #enum
- #import
The correct answer is (b) #define. In C, the #define preprocessor directive is used to define symbolic names or constants. These names can simplify your code and make it more readable.
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.
What is the purpose of the 'switch' statement in C?
- To perform iterative loops
- To handle exceptions
- To provide multiple choices
- To enhance code readability
The 'switch' statement in C is used to provide multiple choices based on the value of an expression. It allows for a concise way to write code when there are multiple possible execution paths. Each 'case' represents a different possible value of the expression, improving code readability and maintainability, especially when dealing with menu-driven programs or handling different options.
In C, subtracting two pointers that point to elements of the same array yields a result of type ________.
- double
- int
- ptrdiff_t
- size_t
In C, subtracting two pointers that point to elements of the same array yields a result of type ptrdiff_t. This type represents the signed integral difference between the two pointers. It's important to use ptrdiff_t when performing pointer subtraction to ensure portability and accurate results, especially in situations involving pointer arithmetic.
The memory consumed by an array declared as float arr[10][20]; is ________.
- 2000 bytes
- 400 bytes
- 80 bytes
- 800 bytes
The memory consumed by a two-dimensional array is calculated by multiplying the number of rows by the number of columns and then multiplying it by the size of the data type. In this case, it's 10 (rows) * 20 (columns) * 4 bytes (float) = 800 bytes.
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.