1.
What are not qualifiers in C?
Correct Answer
B. Const
Explanation
Const is a qualifier in C that is used to declare a variable as a constant, meaning its value cannot be changed once it is assigned. Static and volatile are also qualifiers in C, but they are not included in the list of options given. Therefore, the correct answer is Const.
2.
Which of the following is not the usual practice in declaring variables
as volatile?
Correct Answer
C. Static variables.
Explanation
Static variables are not typically declared as volatile because they are not shared between multiple tasks or threads. Volatile is used to indicate that a variable may be modified by external sources, such as interrupts or other threads, and therefore needs to be accessed directly from memory rather than from a cached value. Static variables, on the other hand, are local to a specific function or module and are not accessed by multiple tasks or threads. Therefore, there is no need to declare them as volatile.
3.
What is the output?
int main()
{
int i = 2*3 /4+4/ 4+3- 2+ 5 / 3;
printf("%d",i);
}
Correct Answer
D. None of the above
Explanation
The correct answer is "None of the above". The output of the code is 7. The expression is evaluated from left to right, following the order of operations. First, 2*3 is calculated which equals 6. Then, 6/4 is calculated which equals 1. Next, 4/4 equals 1. Then, 1+1+3-2 equals 3. Finally, 5/3 equals 1. The final result is 3+1 which equals 4. Therefore, the output is 4, not any of the options given.
4.
What is output?
int main()
{
int x[ ] = { 1, 4, 3, 5, 1, 4 };
int *ptr, y;
ptr = x + 4;
y = ptr - x;
printf("%d",y);
}
Correct Answer
C. 4
Explanation
The code initializes an array "x" with values {1, 4, 3, 5, 1, 4}. It then declares a pointer variable "ptr" and an integer variable "y". The pointer "ptr" is assigned the address of the element at index 4 of array "x". The variable "y" is assigned the difference between the address of "ptr" and the address of the first element of array "x". Finally, the value of "y" is printed, which is 4.
5.
What is the output?
int main()
{
char *s="Abcat";
printf("%s",s+s[1]-s[3]);
}
Correct Answer
C. Bcat
Explanation
The code is using pointer arithmetic to calculate the address of the start of a substring within the string "Abcat". By subtracting the ASCII values of the characters 'c' and 'A' from the address of 's', it is able to find the address of the substring "bcat". The printf statement then prints this substring, resulting in the output "bcat".
6.
The “const” feature can be applied to?
Correct Answer
D. All of the above
Explanation
The "const" feature can be applied to an array argument, an identifier, and an array. This means that all three options mentioned in the question can have the "const" feature applied to them.
7.
What is the correct value to return to the operating system upon the successful?
Correct Answer
D. None of the above
Explanation
None of the given options (Null, 1, -1) is a correct value to return to the operating system upon success. The correct value to return would depend on the specific context and requirements of the operating system or program.
8.
What is the output ?void f(char *);int main(int argc, char** argv){f("123");}void f(char a[]){if(a[1] =='\0') return;f(a+1);f(a+1);printf("%c", a[1]);}
Correct Answer
C. 332
Explanation
The function f is called with the string "123" as an argument. In the function f, the condition a[1] == '\0' is checked. Since a[1] is not equal to '\0', the function calls itself recursively twice, each time with the argument a+1. This means that the function f is called with "23" and then with "3". When the condition a[1] == '\0' is finally true, the function returns. The printf statement then prints the value of a[1], which is '3'. Therefore, the output is "332".
9.
What is the output?
int main(void)
{
static char food[] ="Yummy";
char *ptr;
ptr = food+strlen(food);
printf("%p",ptr);
return 0;
}
Correct Answer
B. Address of y
Explanation
The code initializes a static character array named "food" with the value "Yummy". It then declares a character pointer "ptr" and assigns it the address of the last character in the "food" array using the "strlen" function. Finally, it prints the value of "ptr" using the "%p" format specifier, which is the hexadecimal representation of the memory address where the character 'y' is stored. Therefore, the output will be the address of the character 'y'.
10.
Int main(void){ int x = 2, y, z; x *= 3 + 2; x *= y = z = 4; printf("%d \n", x); x = y == z; printf("%d \n", x); return 0;}
Correct Answer
A. 40,1
Explanation
The code starts by assigning the value 2 to variable x. Then, it multiplies x by the result of 3 + 2, which is 5, so x becomes 10. Next, it multiplies x by the result of y = z = 4, which is also 4. Therefore, x becomes 40. The first printf statement prints the value of x, which is 40. Then, the code assigns the result of y == z to x. Since y and z are both 4, the result is 1 (true). Therefore, the second printf statement prints the value of x, which is 1.