Computer Knowledge
Programming, networking, database and OS questions
65 Questions 5 Topics Take Test
Advertisement
Showing 61–65 of 65 questions
Q.61 Hard C Programming
What is the correct way to declare a constant pointer to a constant integer?
A const int * const ptr;
B const int const *ptr;
C int const * const ptr;
D Both A and C
Correct Answer:  D. Both A and C
EXPLANATION

Both declarations are equivalent. 'const int * const ptr' and 'int const * const ptr' declare a constant pointer to a constant integer. The first const makes the integer constant, the second const makes the pointer constant.

Take Test
Q.62 Hard C Programming
What is the output of the following C code?
#include
int main() {
int a = 5;
printf("%d %d %d", a++, ++a, a);
return 0;
}
A 5 7 7
B 6 7 7
C 5 6 6
D Undefined behavior
Correct Answer:  D. Undefined behavior
EXPLANATION

This code contains undefined behavior because variable 'a' is modified multiple times (a++, ++a) without intervening sequence points in the same expression. The order of evaluation is unspecified, making the result compiler-dependent.

Take Test
Q.63 Hard Data Structures
In a B-tree of order m, what is the maximum number of children a non-leaf node can have?
A m
B m - 1
C m + 1
D 2m
Correct Answer:  C. m + 1
EXPLANATION

A B-tree of order m has a maximum of m children per node, which means it can have a maximum of (m-1) keys.

Each node can have between ⌈m/2⌉ and m children (for non-leaf nodes), ensuring balance. B-trees are commonly used in database indexing and file systems because they minimize disk I/O operations through their multi-level structure and balanced properties.

Take Test
Q.64 Hard C Programming
What is the purpose of the volatile keyword in C?
A To prevent a variable from being modified by the program
B To inform the compiler that a variable may change unexpectedly and should not be optimized out or cached in registers
C To allocate memory on the stack instead of the heap
D To make a variable accessible across all files in a project
Correct Answer:  B. To inform the compiler that a variable may change unexpectedly and should not be optimized out or cached in registers
EXPLANATION

The volatile keyword tells the compiler that a variable's value may change at any time (due to external factors like hardware registers, signal handlers, or multi-threading) and should be read from memory every time it's accessed, rather than being optimized by the compiler or cached in a register.

Take Test
Q.65 Hard C Programming
Consider a structure with bit fields. What will be the size of the following structure in bytes?

struct demo {
unsigned int a : 5;
unsigned int b : 3;
unsigned int c : 4;
unsigned int d : 7;
};
A 1 byte
B 2 bytes
C 4 bytes
D 8 bytes
Correct Answer:  C. 4 bytes
EXPLANATION

Bit fields in C are packed into the smallest integral type that can accommodate them.

Here, a(5) + b(3) + c(4) + d(7) = 19 bits total.

Since 19 bits exceed 16 bits but fit within 32 bits, the compiler allocates 4 bytes (32 bits) for this structure, following standard packing rules.

Take Test
IGET
iget AI
Online · Ask anything about exams
Hi! 👋 I'm your iget AI assistant.

Ask me anything about exam prep, MCQ solutions, study tips, or strategies! 🎯
UPSC strategy SSC CGL syllabus Improve aptitude NEET Biology tips