Computer Knowledge — C Programming
Programming, networking, database and OS questions
200 Questions 5 Topics Take Test
Advertisement
Showing 21–30 of 200 questions in C Programming
Q.21 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.22 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.23 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
Q.24 Medium C Programming
What is the output of: int x = 5; int y = ++x; ?
A x = 5, y = 5
B x = 6, y = 6
C x = 6, y = 5
D x = 5, y = 6
Correct Answer:  B. x = 6, y = 6
EXPLANATION

The pre-increment operator ++x increments x first (from 5 to 6), then assigns the new value to y. So x = 6 and y = 6.

Take Test
Q.25 Easy C Programming
What is the correct way to declare a pointer to an integer?
A int p*;
B int *p;
C *int p;
D pointer int p;
Correct Answer:  B. int *p;
EXPLANATION

The correct syntax is 'int *p;' where int is the data type, * indicates pointer, and p is the pointer variable name.

Take Test
Q.26 Medium C Programming
What is the output of: int a = 10, b = 20; int *p = &a, *q = &b; printf("%d", *p + *q);?
A 10
B 20
C 30
D Error
Correct Answer:  C. 30
EXPLANATION

*p dereferences to a (10) and *q dereferences to b (20). Adding them: 10 + 20 = 30. Pointer arithmetic is used correctly here.

Take Test
Q.27 Hard C Programming
In a struct, how is memory allocated for union members?
A All members get their own separate memory
B Members share the same memory location
C Memory allocated based on member frequency
D Dynamic allocation only
Correct Answer:  B. Members share the same memory location
EXPLANATION

In a union, all members share the same memory location. The size of the union equals the size of the largest member. Only one member can hold a value at a time.

Take Test
Q.28 Hard C Programming
What will be the result of: 5 % 2 * 3 / 2?
A 1
B 2
C 1.5
D 3
Correct Answer:  B. 2
EXPLANATION

Modulus, multiplication, and division have equal precedence (left-to-right): (5 % 2) = 1, then (1 * 3) = 3, then (3 / 2) = 1 (integer division). Answer is 1, not 2. Correction: 1 is correct.

Take Test
Q.29 Hard C Programming
What is printed by: char s[] = "hello"; printf("%zu", sizeof(s));?
A 5
B 6
C 4
D Undefined
Correct Answer:  B. 6
EXPLANATION

sizeof(s) includes the null terminator '\0'. "hello" has 5 characters + 1 null terminator = 6 bytes. If s was a pointer, sizeof would give pointer size.

Take Test
Q.30 Hard C Programming
Consider: int *p, q; What is the type of q?
A Pointer to int
B Integer
C Pointer to pointer
D Character
Correct Answer:  B. Integer
EXPLANATION

Only p is declared as a pointer (int *p). The variable q is declared as a regular integer (int q). The * applies only to p in this declaration.

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