Home Subjects Computer Knowledge

Computer Knowledge

Programming, networking, database and OS questions

150 Q 2 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 121–130 of 150
Topics in Computer Knowledge
All C Programming 200 Database/SQL 100
Q.121 Medium C Programming
Which of the following correctly declares a pointer to an integer?
A int *ptr;
B *int ptr;
C ptr *int;
D int ptr*;
Correct Answer:  A. int *ptr;
EXPLANATION

The correct syntax for declaring a pointer to an integer is 'int *ptr;' where the asterisk (*) indicates that ptr is a pointer. The placement of * before the variable name is crucial.

Take Test
Q.122 Medium C Programming
What is the output of: int x = 10; printf("%d", x++); printf("%d", x);
A 1010
B 1011
C 910
D 111
Correct Answer:  B. 1011
EXPLANATION

x++ is post-increment. First printf uses current value (10), then x is incremented. Second printf uses new value (11). Output: 1011

Take Test
Q.123 Medium C Programming
What is the output of the following code?
for(int i = 1; i
A 1 2 3
B 1 3
C 2 3
D 1
Correct Answer:  B. 1 3
EXPLANATION

When i = 1, it prints 1. When i = 2, continue skips the printf() and moves to the next iteration. When i = 3, it prints 3. Output: 1 3

Take Test
Q.124 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.125 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.126 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.127 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.128 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.129 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.130 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