Home Subjects Computer Knowledge

Computer Knowledge

Programming, networking, database and OS questions

150 Q 2 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 51–60 of 150
Topics in Computer Knowledge
All C Programming 200 Database/SQL 100
Q.51 Medium C Programming
Consider a structure: struct Point { int x; int y; }; If p is a pointer to this structure and we want to access member x, which notation is INCORRECT?
A p->x
B (*p).x
C p.x
D All are correct when used appropriately
Correct Answer:  C. p.x
EXPLANATION

When p is a pointer to a structure, we cannot use p.x (dot notation) directly. The correct ways are: p->x (arrow operator) or (*p).x (dereference then dot operator). The notation p.x would be used only if p were a structure variable, not a pointer. Therefore, p.x is incorrect when p is a pointer.

Take Test
Q.52 Medium C Programming
If arr[5] = {1, 2, 3, 4, 5}, what will be the value of *(arr + 3)?
A 3
B 4
C 5
D 2
Correct Answer:  B. 4
EXPLANATION

In array notation, arr is a pointer to the first element. *(arr + 3) dereferences the pointer that points to the 4th element (index 3). Since array indexing is 0-based: arr[0]=1, arr[1]=2, arr[2]=3, arr[3]=4. Therefore, *(arr + 3) = 4.

Take Test
Q.53 Medium C Programming
What is the primary difference between malloc() and calloc() functions in C?
A malloc() allocates memory while calloc() deallocates it
B malloc() doesn't initialize memory, while calloc() initializes it to zero
C calloc() can only allocate fixed-size blocks
D malloc() requires two arguments while calloc() requires one
Correct Answer:  B. malloc() doesn't initialize memory, while calloc() initializes it to zero
EXPLANATION

Both malloc() and calloc() allocate dynamic memory. The key difference is that malloc() allocates uninitialized memory (contains garbage values), while calloc() allocates memory and initializes all bytes to zero. calloc() also takes two arguments (number of elements and size of each element), while malloc() takes one (total bytes needed).

Take Test
Q.54 Medium C Programming
What will be the output of the following code?
int *ptr;
int arr[3] = {10, 20, 30};
ptr = arr;
printf("%d", *(ptr + 1));
A 10
B 20
C 30
D Compilation Error
Correct Answer:  B. 20
EXPLANATION

ptr points to arr[0] (value 10). ptr + 1 points to arr[1] (value 20). *(ptr + 1) dereferences this pointer, giving 20.

Take Test
Q.55 Medium C Programming
What is the output of the following code?
int x = 5;
int y = ++x;
printf("%d %d", x, y);
A 5 5
B 6 6
C 6 5
D 5 6
Correct Answer:  B. 6 6
EXPLANATION

++x is pre-increment, which increments x before assignment. So x becomes 6, then y is assigned 6. Both x and y are 6.

Take Test
Q.56 Medium C Programming
How is a two-dimensional array typically stored in memory in C?
A Column-major order
B Random order
C Row-major order
D Scattered order
Correct Answer:  C. Row-major order
EXPLANATION

C uses row-major order to store 2D arrays in memory. The elements are stored row by row sequentially in memory.

Take Test
Q.57 Medium C Programming
Which loop construct will execute at least once even if the condition is false?
A while loop
B for loop
C do-while loop
D All of the above
Correct Answer:  C. do-while loop
EXPLANATION

The do-while loop executes the body first and then checks the condition, ensuring at least one execution. while and for loops check the condition first.

Take Test
Q.58 Medium C Programming
What will be the value of x after executing: int x = 10; x += 5; x *= 2; ?
A 25
B 30
C 20
D 40
Correct Answer:  B. 30
EXPLANATION
Step 1: x = 10. Step 2: x += 5 means x = x + 5 = 15. Step 3: x *= 2 means x = x * 2 = 15 * 2 = 30.
Take Test
Q.59 Medium C Programming
Which of the following correctly defines a structure in C?
A struct { int a; float b; } MyStruct;
B structure MyStruct { int a; float b; };
C struct MyStruct { int a; float b; };
D class MyStruct { int a; float b; };
Correct Answer:  C. struct MyStruct { int a; float b; };
EXPLANATION

The correct syntax uses the 'struct' keyword followed by the structure name and then the member declarations enclosed in braces.

Take Test
Q.60 Medium C Programming
What is the purpose of the free() function in C?
A To allocate memory dynamically
B To deallocate or release dynamically allocated memory
C To initialize variables
D To compare two memory blocks
Correct Answer:  B. To deallocate or release dynamically allocated memory
EXPLANATION

The free() function deallocates (releases) memory that was previously allocated using malloc(), calloc(), or realloc().

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