Showing 111–120 of 309 questions
Q.111
Medium
C Programming
What will be the output of: int x = 5; printf("%d", x
Explanation:
The left shift operator (<<) shifts bits to the left by 1 position, which is equivalent to multiplying by 2. So 5 << 1 = 10.
Q.112
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].
Q.113
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.
What will be the output of: #define MAX 10; int x = MAX; printf("%d", x);
A
10
B
Error
C
MAX
D
Undefined
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)
Q.115
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.
What will be the output of: int x = 10; int y = x++ + ++x; printf("%d", y);
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).
Q.117
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
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.
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.
What will be the output of: printf("%d", 5/2);
Explanation:
Integer division truncates the decimal part. 5/2 = 2 (not 2.5) because both operands are integers.
What does the getchar() function do?
A
Reads a single character from input
B
Reads a string from input
C
Displays a character
D
Returns ASCII value of a character
Correct Answer:
A. Reads a single character from input
Explanation:
getchar() reads a single character from standard input (stdin) and returns its ASCII value.