Computer Knowledge
Aptitude · Reasoning · English · CS — Corporate & Campus Interview Prep
309 Questions 5 Topics Take Test
Advertisement
Showing 51–60 of 309 questions
Q.51 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.52 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.53 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.54 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.55 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
Advertisement
Q.56 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.57 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.58 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.59 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.60 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
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