Home Subjects Computer Knowledge

Computer Knowledge

Programming, networking, database and OS questions

150 Q 2 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 91–100 of 150
Topics in Computer Knowledge
All C Programming 200 Database/SQL 100
Q.91 Medium C Programming
What is the purpose of the break statement in a switch case?
A To exit the program
B To exit the current loop or switch
C To skip the next statement
D To pause execution
Correct Answer:  B. To exit the current loop or switch
EXPLANATION

The break statement terminates the current loop or switch block and transfers control to the statement following the loop or switch. Without it, execution continues to the next case (fall-through).

Take Test
Q.92 Medium C Programming
Which function is used to allocate memory dynamically at runtime?
A alloc()
B malloc()
C memalloc()
D allocate()
Correct Answer:  B. malloc()
EXPLANATION

malloc() is the standard C library function for dynamic memory allocation. It returns a void pointer to the allocated memory block, which can be cast to the required data type.

Take Test
Q.93 Medium C Programming
What is the output of: int arr[5]; printf("%d", sizeof(arr));
A 5
B 10
C 20
D 1
Correct Answer:  C. 20
EXPLANATION

sizeof(arr) returns the total size of the array in bytes. An array of 5 integers, where each int is 4 bytes, equals 5 × 4 = 20 bytes.

Take Test
Q.94 Medium C Programming
What will be the output of: char c = 'A'; printf("%d", c);
A 65
B A
C Error
D 1
Correct Answer:  A. 65
EXPLANATION

The %d format specifier prints the ASCII value of the character. 'A' has ASCII value 65.

Take Test
Q.95 Medium C Programming
What is the output of: int arr[] = {1,2,3,4,5}; printf("%d", sizeof(arr)/sizeof(arr[0]));
A 5
B 20
C 4
D Depends on compiler
Correct Answer:  A. 5
EXPLANATION

sizeof(arr) gives total size of array. sizeof(arr[0]) gives size of one element. Dividing gives the number of elements: 20/4 = 5.

Take Test
Q.96 Medium C Programming
Which function is used to read a string from standard input?
A gets()
B fgets()
C scanf()
D All of the above
Correct Answer:  D. All of the above
EXPLANATION

All three functions can read strings, though gets() is deprecated due to security issues. fgets() is safer as it limits input size.

Take Test
Q.97 Medium C Programming
What is the purpose of the void pointer in C?
A To store addresses of any data type
B To declare functions with no return
C To declare variables with no value
D All of the above
Correct Answer:  D. All of the above
EXPLANATION

The void pointer is a generic pointer that can hold addresses of any data type. void is also used for functions returning nothing and parameters.

Take Test
Q.98 Medium C Programming
Consider the code: int arr[10]; int *p = arr; What is p[5]?
A Address of arr[5]
B Value at arr[5]
C 5th element after arr
D Garbage value
Correct Answer:  B. Value at arr[5]
EXPLANATION

p points to arr, so p[5] is equivalent to *(p+5) which gives the value at arr[5].

Take Test
Q.99 Medium C Programming
What will be the output of: int x = 5; printf("%d", x
A 5
B 10
C 20
D 2
Correct Answer:  B. 10
EXPLANATION

The left shift operator (<<) shifts bits to the left by 1 position, which is equivalent to multiplying by 2. So 5 << 1 = 10.

Take Test
Q.100 Medium C Programming
What will be the output of the following code?
int a = 5;
int b = ++a + a++;
printf("%d", b);
A 11
B 12
C 10
D 13
Correct Answer:  B. 12
EXPLANATION

++a increments a to 6 and returns 6. Then a++ returns 6 and increments a to 7. So b = 6 + 6 = 12.

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