Which preprocessor directive would be used to conditionally compile certain blocks of code?
- #define directive
- #ifdef directive
- #include directive
- #pragma directive
The #ifdef directive is used to conditionally compile code based on whether a certain macro has been defined. It allows you to include or exclude specific code blocks based on preprocessor macros.
When dealing with an array of structures in C, what does each element of the array represent?
- A character array
- A floating-point number
- A function pointer
- A single structure instance
Each element of the array represents a single instance of the structure.
When designing a data packet structure for network communication, using ________ can help to minimize the packet size.
- Compression
- Encapsulation
- Fragmentation
- Segmentation
Encapsulation is a technique used to bundle data and functions into a single unit. It can help minimize the packet size by encapsulating data in a structured format for transmission over the network.
What is the purpose of the 'sizeof' operator in C?
- It returns the address of a variable.
- It returns the size of a variable in bytes.
- It returns the type of a variable.
- It returns the value of a variable.
The 'sizeof' operator in C is used to determine the size (in bytes) of a variable or a data type. It is often used to allocate memory or work with data structures.
What does the strlen function from the C standard library do?
- Allocates memory for a new string
- Calculates the length of a string
- Compares two strings
- Copies one string to another
The strlen function in C calculates the length of a string by counting the number of characters until it reaches a null-terminator. It does not allocate memory or perform string copying.
How does a double pointer differ from a single pointer?
- Can store multiple values
- Points to a memory address
- Points to another pointer
- Stores double the data
A double pointer in C points to the memory address of a pointer, while a single pointer points to a single memory address. It allows for indirection, which can be useful in certain scenarios.
An array of structures can be used to represent a collection of ________ that share the same attributes but have different values.
- Constants
- Functions
- Objects
- Variables
Arrays of structures in C are commonly used to represent a collection of objects (or variables) that share the same attributes but have different values, making them an efficient way to manage related data.
Which statement is true regarding the difference between inline functions and macros in C?
- Inline functions can have local variables
- Inline functions cannot be used with conditional compilation
- Macros are preprocessed
- Macros are type-safe
Macros in C are preprocessed, meaning they are replaced by their definitions before compilation. This can lead to unexpected behavior and debugging challenges. In contrast, inline functions are compiled as proper functions with type safety and can have local variables.
How does the 'return' statement affect the flow of control within a loop?
- The 'return' statement exits the loop, returning control to the calling function or method.
- The 'return' statement has no impact on the flow of control within a loop.
- The 'return' statement skips the next iteration of the loop.
- The 'return' statement terminates the entire program when used within a loop.
The 'return' statement is used to exit a function or method prematurely and return a value. When a 'return' statement is encountered within a loop, it immediately exits the loop and returns control to the calling function or method. This can be useful for ending a loop under certain conditions or returning a value from the loop.
You are developing a program to manage the seating arrangement in a movie theater with rows and columns. How would you represent the seats using arrays?
- 1D Array
- 2D Array
- Linked List
- Queue (FIFO)
Seats in a theater can be efficiently represented using a 2D array, with rows and columns, making it easy to access and manage each seat's status.
What function can be used to find the current position of the file pointer in a file?
- fseek()
- readPosition()
- getCurrentPointer()
- filePosition()
The correct function to find the current position of the file pointer in a file is 'fseek()'. It allows you to set the file position indicator to a specific location in the file and returns the current position. The other options are not valid functions for this purpose.
How does the strtok() function work in C?
- It calculates the length of a string
- It converts a string to uppercase
- It performs a binary search
- It splits a string into multiple substrings based on a delimiter
The strtok() function in C is used to split a string into multiple substrings based on a specified delimiter. It maintains state between calls, making it useful for tokenizing strings.