- fseek
- rewind
- fgetpos
Explanation:
The correct answer is b. The purpose of the fseek function is to update the status record for a given file stream.
- In C, which of the following is used to describe the memory layout of the program?
- Stack, Heap, Text, BSS, Data
- Stack, Data, Heap, Text, BSS
- Text, BSS, Data, Heap, Stack
- Data, Text, BSS, Stack, Heap
Explanation:
The correct answer is c. The memory structure of a C program typically consists of the following blocks: text (code), BSS (uninitialized data), data (initialized data), stack (dynamic memory), and stack (local variables and function calls).
- Which storage classes in C will have zero as a default value for uninitialized variables?
- auto
- register
- static
- extern
Explanation:
The accurate response is c. Variables defined with a static storage class will automatically be set to null if not explicitly initialized.
- Which operator in C is employed to access the structure member via the pointer?
Explanation:
The correct answer is b. This -> operator in C is used to access members of a structure using a pointer.
- Which C standard library function is used to convert a string to an integer?
- strtol
- itoa
- sprintf
- atof
Explanation:
The correct answer is a. The strtol function is an appropriate choice to convert a string to an integer type because it can convert a string to an integer length, while atoi can convert a string to an int. The other functions serve different purposes.
- In C, what does "bit-field" refers to?
- A field in a structure that occupies multiple bytes.
- A field in a structure that occupies a specified number of bits.
- A type of array that holds bits.
- A variable that can only hold binary values (0 or 1).
Explanation:
The correct answer is b. A bit field in C is a member of a system in which a fixed number of bits are allocated instead of a traditional byte size, thus using memory more efficiently.
- What is the objective of attribute((packed))attribute in C?
- To align structure members on their natural boundaries.
- To optimize the size of structures by eliminating padding.
- To ensure variables are placed in read-only memory.
- To enable a variable to be accessed by multiple threads.
Explanation:
The accurate response is option b. To expand the structure's size, the directive((packed)) attribute instructs the compiler to merge array components without inserting padding between them.
If the fopen function fails to open the file, it returns NULL.
Explanation:
The correct answer is b. The fopen function returns a pointer to FILE object. If in case it fails to open the file, it will return NULL.
- What is meant by the "dangling pointer" in C?
- A pointer to an authorised memory address.
- A pointer without an initialization.
- A pointer pointing to a released memory region.
- A pointer pointing to a different kind of memory location.
Explanation:
The correct answer is c. A dangling pointer is a pointer thaLogic Practices to a freed memory region and it behaves undefinedly.
- What does C's #include directive serve as?
- To include user-defined functions.
- To define constants.
- To include a file's or library's contents.
- To introduce a new variable.
Explanation:
The correct answer is c. In C implementations, the #include directive is employed to import the contents of an existing file or library. It is commonly used to incorporate header files, which contain function declarations and macro definitions.
- Which method in c is used to find the length of string?
- strlen
- strcpy
- strcat
- strcmp
Explanation:
The correct answer is a. In C, the strlen method is used to find the length of a string. It will return the number of characters in the string minus the null terminator.
- Which of the following statements about union in C is true?
- Multiple values can be stored simultaneously in the same union.
- Only one value can be stored in the union at a time.
- The total size of a union is the sum of the sizes of its parts.
- The size of the union is equal to the size of its largest member.
Explanation:
The accurate option is b. Within the C programming language, a union has the capability to utilize a singular memory address for multiple members. As a result, the size of the union is dictated by the largest member it contains, allowing for the storage of only a single value at any given time.