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 91–100 of 200
Topics in Computer Knowledge
All C Programming 200 Database/SQL 100
Q.91 Easy C Programming
What will be the output of: printf("%d", 5/2);
A 2.5
B 2
C 3
D 2.0
Correct Answer:  B. 2
EXPLANATION

Integer division truncates the decimal part. 5/2 = 2 (not 2.5) because both operands are integers.

Take Test
Q.92 Easy C Programming
Which of the following correctly initializes a 2D array?
A int arr[3][3] = {1,2,3,4,5,6,7,8,9};
B int arr[3][3] = {{1,2,3},{4,5,6},{7,8,9}};
C Both A and B
D Neither A nor B
Correct Answer:  C. Both A and B
EXPLANATION

Both syntaxes are correct. C allows initializing 2D arrays with or without explicit braces for each row.

Take Test
Q.93 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.94 Hard C Programming
What will be the output of: int x = 10; int y = x++ + ++x; printf("%d", y);
A 20
B 21
C 22
D 23
Correct Answer:  B. 21
EXPLANATION

x++ returns 10 and increments x to 11. ++x increments x to 12 and returns 12. So y = 10 + 12 = 22. Wait, let me recalculate: y = 10 + 11 = 21 (as x becomes 11 after first post-increment, then ++x makes it 12).

Take Test
Q.95 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.96 Easy C Programming
What will be the output of: #define MAX 10; int x = MAX; printf("%d", x);
A 10
B Error
C MAX
D Undefined
Correct Answer:  A. 10
EXPLANATION

The #define directive replaces MAX with 10 during preprocessing. So x = 10 and output is 10. (Note: semicolon after MAX is not needed but doesn't affect the output)

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 Easy C Programming
What will be the output of: char *s = "Hello"; printf("%d", strlen(s));
A 5
B 6
C 4
D Error
Correct Answer:  A. 5
EXPLANATION

strlen() counts characters excluding the null terminator. "Hello" has 5 characters, so strlen(s) returns 5.

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