Home Subjects Computer Knowledge C Programming

Computer Knowledge
C Programming

Programming, networking, database and OS questions

200 Q 2 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 151–160 of 200
Topics in Computer Knowledge
All C Programming 200 Database/SQL 100
Q.151 Medium C Programming
Consider the following code:
int arr[] = {1, 2, 3, 4, 5};
int *ptr = arr;
What is the value of *(ptr + 2)?
A 1
B 2
C 3
D 4
Correct Answer:  C. 3
EXPLANATION

ptr points to arr[0]. ptr + 2 points to arr[2]. *(ptr + 2) dereferences to get the value at arr[2], which is 3. Pointer arithmetic moves by the size of the data type (integers).

Take Test
Q.152 Medium C Programming
What is the correct syntax to open a file in C?
A FILE *fp = fopen("file.txt", "r");
B FILE fp = open("file.txt", "r");
C fopen *fp = FILE("file.txt", "r");
D FILE fp = fopen("file.txt");
Correct Answer:  A. FILE *fp = fopen("file.txt", "r");
EXPLANATION

The correct syntax is FILE *fp = fopen("filename", "mode");. fopen() returns a pointer to a FILE structure, and the mode string specifies how to open the file ("r" for read, "w" for write, etc.).

Take Test
Q.153 Easy C Programming
What will be the value of x after: int x = 5; x += 3;
A 3
B 5
C 8
D 53
Correct Answer:  C. 8
EXPLANATION

The += operator is a compound assignment operator. x += 3 is equivalent to x = x + 3. Therefore, 5 + 3 = 8.

Take Test
Q.154 Medium C Programming
What is the difference between calloc() and malloc() in C?
A calloc() initializes memory to 0, malloc() does not
B malloc() is faster than calloc()
C calloc() takes two arguments, malloc() takes one
D All of the above
Correct Answer:  D. All of the above
EXPLANATION

calloc() allocates memory and initializes all bytes to 0, takes (number of elements, size of each element). malloc() just allocates memory without initialization and takes total size. calloc() is slightly slower due to initialization.

Take Test
Q.155 Easy C Programming
How many times will the loop execute?
for(int i = 0; i < 5; i++)
A 4 times
B 5 times
C 6 times
D Infinite times
Correct Answer:  B. 5 times
EXPLANATION

The loop initializes i to 0 and continues while i < 5. Values of i: 0, 1, 2, 3, 4. After i becomes 5, the condition is false, so the loop executes 5 times.

Take Test
Q.156 Medium C Programming
What is the scope of a variable declared inside a function in C?
A Global scope
B Local/Function scope
C Static scope
D External scope
Correct Answer:  B. Local/Function scope
EXPLANATION

Variables declared inside a function have local scope (also called function scope). They are only accessible within that function and are destroyed when the function returns.

Take Test
Q.157 Easy C Programming
What is the output of sizeof(char) in C?
A 0 bytes
B 1 byte
C 2 bytes
D Varies by compiler
Correct Answer:  B. 1 byte
EXPLANATION

By the C standard, sizeof(char) is always 1 byte. A char is the smallest addressable unit in C and is defined to be 1 byte.

Take Test
Q.158 Medium C Programming
Which of the following correctly declares a pointer to a pointer?
A int *ptr;
B int **ptr;
C int &ptr;
D int ***ptr;
Correct Answer:  B. int **ptr;
EXPLANATION

A pointer to a pointer is declared using two asterisks (). int ptr declares a pointer that points to another pointer that points to an integer.

Take Test
Q.159 Medium C Programming
What is the correct way to initialize an array of 5 integers with all elements as 0?
A int arr[5] = {};
B int arr[5] = {0};
C Both A and B
D int arr[5] = {0, 0, 0, 0, 0};
Correct Answer:  C. Both A and B
EXPLANATION

Both {} and {0} will initialize all array elements to 0. When you provide fewer initializers than array size, remaining elements are automatically set to 0.

Take Test
Q.160 Medium C Programming
What will be the memory size of the following struct?
struct Point { int x; char c; int y; }
A 9 bytes
B 10 bytes
C 12 bytes
D 16 bytes
Correct Answer:  C. 12 bytes
EXPLANATION

Due to memory alignment/padding: int x (4 bytes), char c (1 byte) + 3 bytes padding, int y (4 bytes) = 12 bytes total. The compiler adds padding to align data members to their natural boundaries for efficient memory access.

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