Showing 171–180 of 309 questions
Which of the following is NOT a valid variable name in C?
A
_myVar
B
myVar123
C
123myVar
D
my_var
Correct Answer:
C. 123myVar
Explanation:
Variable names in C cannot start with a digit. They must begin with a letter (a-z, A-Z) or underscore (_). '123myVar' is invalid.
What will be the output of: printf("%d", 5 + 3 * 2);?
Explanation:
Operator precedence: multiplication (*) is performed before addition (+). So: 3 * 2 = 6, then 5 + 6 = 11.
What keyword is used to create a pointer variable in C?
Explanation:
The asterisk (*) symbol is used to declare pointer variables. For example: int *ptr; declares a pointer to an integer.
Q.174
Medium
C Programming
What is the correct syntax to pass a 2D array to a function in C?
A
func(int arr[][])
B
func(int arr[rows][cols])
C
func(int arr[][cols])
D
func(int **arr)
Correct Answer:
C. func(int arr[][cols])
Explanation:
When passing a 2D array to a function, the number of columns must be specified, but the number of rows is optional. Option C is the standard correct syntax.
Q.175
Medium
C Programming
What will be printed by: int x = 5; printf("%d", ++x + x++);?
Explanation:
++x increments x to 6 (pre-increment), then x++ returns 6 and increments x to 7. So: 6 + 6 = 12. Post-increment returns the old value.
Q.176
Medium
C Programming
Which of the following correctly uses the ternary operator?
A
x = (a > b) : a : b;
B
x = (a > b) ? a : b;
C
x = a > b ? a : b
D
x = (a > b) -> a : b;
Correct Answer:
B. x = (a > b) ? a : b;
Explanation:
The ternary operator syntax is: condition ? value_if_true : value_if_false. Option B is the only correctly formatted statement.
Q.177
Medium
C Programming
What is the purpose of the const keyword when used with a pointer?
A
To make the pointer variable unchangeable
B
To make the pointed data unchangeable
C
Both A and B depending on placement
D
To allocate memory in the constant segment
Correct Answer:
C. Both A and B depending on placement
Explanation:
const int *ptr makes the data constant (const int * ptr). int * const ptr makes the pointer constant. The position of const matters.
Q.178
Medium
C Programming
What is the return type of malloc() function?
A
int*
B
char*
C
void*
D
size_t
Explanation:
malloc() returns a void pointer (void*), which can be cast to any data type pointer as needed by the programmer.
Q.179
Medium
C Programming
In the expression: int arr[10]; what is arr[5]?
A
A pointer to the 5th element
B
The value at memory address arr + 5
C
Both A and B are equivalent
D
An integer value between 0-10
Correct Answer:
C. Both A and B are equivalent
Explanation:
arr[5] accesses the element at index 5, which is at memory address (arr + 5). Array name arr acts as a pointer to the first element.
Consider: int *p, q; What is the type of q?
A
Pointer to int
B
Integer
C
Pointer to pointer
D
Character
Correct Answer:
B. Integer
Explanation:
Only p is declared as a pointer (int *p). The variable q is declared as a regular integer (int q). The * applies only to p in this declaration.