1.
main()
{
char *ptr1
= “abcdef”;
ptr1 = ptr1
+ (strlen(ptr1)-1);
printf(“%c”,--*ptr1--);
printf(“%c”,--*--ptr1);
printf(“%c”,--*(ptr1--));
printf(“%c”,--*(--ptr1));
printf(“%c”,*ptr1);
}
Correct Answer
C. Ecbaa
Explanation
The code initializes a pointer `ptr1` to point to the string "abcdef". The expression `ptr1 = ptr1 + (strlen(ptr1)-1)` moves the pointer to the last character of the string, which is 'f'.
In the first `printf` statement, `--*ptr1--` decrements the value of 'f' to 'e' and then moves the pointer to the previous character, 'e'.
In the second `printf` statement, `--*--ptr1` first moves the pointer to the previous character, 'd', and then decrements its value to 'c'.
In the third `printf` statement, `--*(ptr1--)` decrements the value of 'c' to 'b' and then moves the pointer to the previous character, 'a'.
In the fourth `printf` statement, `--*(--ptr1)` first moves the pointer to the previous character, 'a', and then decrements its value to 'a'.
Finally, in the fifth `printf` statement, `*ptr1` simply prints the value of the current character, which is 'a'.
Therefore, the output of the code is "ecbaa".
2.
main ()
{
int a;
a = 3;
e(a);
}
void e(int a)
{
if(n>0) {
e(--n);
printf(“%d”,n);
e(--n);
}
}
Correct Answer
B. 0120
Explanation
The correct answer is 0120. The code starts with the main function and initializes the variable a with the value 3. Then, it calls the function e with the argument a. In the function e, there is a recursive call to e with the argument n decremented by 1. This means that the function e will be called again with the argument 2. Inside the if statement, there is a printf statement that prints the value of n, which is 2. After that, there is another recursive call to e with the argument n decremented by 1 again, which means the function e will be called with the argument 1. This process continues until n becomes 0. So, the output will be 0120.
3.
main()
{
char
a[]=”abcdef”;
char * p =
a;
p++;
p++;
p[2] = ‘z’;
printf(“ %s “,p);
}
Correct Answer
C. Cdzf
Explanation
The code initializes a character array "a" with the string "abcdef" and a character pointer "p" pointing to the first element of "a". The code then increments the pointer "p" twice, making it point to the third element of "a". The third element is then assigned the value 'z'. Finally, the code prints the string starting from the pointer "p", which is "cdzf".
4.
void t1 (char *);
main()
{
char * p;
p =
”abcdef”;
t1(p);
}
void t1(char *q)
{
if(*q != ‘d’)
{
putchar(*q);
t1(q++);
}
}
Correct Answer
C. Infinite a
Explanation
The given code is a recursive function that prints each character of a string until it encounters the character 'd'. In the main function, the string "abcdef" is passed to the t1 function. Inside the t1 function, the condition *q != 'd' is checked. If the condition is true, the character pointed to by q is printed using putchar(*q). Then, the t1 function is called recursively with q incremented by 1 (q++). Since there is no base case or condition to stop the recursion, the function will continue to be called infinitely, printing 'a' repeatedly.
5.
main ()
{
printf
(“%d”, sizeof (65555));
printf(“%d”,sizeof(65555L));
printf(“%d”,sizeof(6.5F));
printf
(“%d”,sizeof (6.5));
printf(“%d”,sizeof(6.5L));
}
Correct Answer
C. 4 4 4 8 10
Explanation
The program is using the sizeof operator to determine the size in bytes of different data types. The sizeof operator returns the size of a data type in bytes.
- sizeof(65555) returns 4 because 65555 is an integer value and the size of an integer is typically 4 bytes.
- sizeof(65555L) returns 4 because 65555L is a long integer value and the size of a long integer is also typically 4 bytes.
- sizeof(6.5F) returns 4 because 6.5F is a float value and the size of a float is typically 4 bytes.
- sizeof(6.5) returns 8 because 6.5 is a double value and the size of a double is typically 8 bytes.
- sizeof(6.5L) returns 10 because 6.5L is a long double value and the size of a long double is typically 10 bytes.
6.
main()
{
int q, i,
j, count;
i=j=0;
q=2;
count = 6;
switch( 3 )
{
case
0:
while
( --count > 0 ) {
case
1:
++j;
case
2:
++i;
case
3: ;
case
4: ;
case
5: ;
}
}
printf(“%d”,i);
printf(“%d”,j);
}
Correct Answer
B. 55
Explanation
The code snippet provided uses a switch statement with the value of 3. Since there is no case for 3, the switch statement does nothing and moves to the next line. The while loop then decrements the count variable until it becomes 0. Inside the while loop, there are cases for 1 and 2 which increment the variables j and i respectively. However, there are no cases for 0, 4, and 5, so these cases do nothing. Therefore, after the while loop, the value of i will be 0 and the value of j will be 2. The correct answer is 55, which is the value of j.
7.
Which
of the following does not have an unary operator?
Correct Answer
C. J
Explanation
The given options include -7, ++j, j, and !i. The unary operator is an operator that operates on a single operand. In this case, the unary operator is the exclamation mark (!) which is used for logical negation. It is applied to the operand i in the expression !i. However, the variable j does not have any unary operator applied to it, making it the correct answer.
8.
A
union consists of a number of elements that
Correct Answer
A. All occupy the same space in memory
Explanation
In a union, all the elements occupy the same space in memory. This means that only one element of the union can be stored at a time, and accessing one element may overwrite the value of another element. This is different from a structure, where each element has its own separate space in memory. The elements in a union can have different types, but they all share the same memory space.
9.
The
int type of constraints are whole numbers in the range
Correct Answer
B. -32768 to 32767
Explanation
The correct answer is -32768 to 32767. This range represents the valid values for the int data type in programming. The int type is used to store whole numbers, and this range ensures that the values fall within the limits of the data type. Values below -32768 or above 32767 would result in an overflow or underflow, potentially causing unexpected behavior in the program. Therefore, the range of -32768 to 32767 is the correct answer for the int type of constraints.
10.
If the variables i,j and k are assigned the
values 5,3 and 2 respectively, then the expression i=j+(k++ =6)+7;
Correct Answer
D. Gives an error message
Explanation
The expression i=j+(k++ =6)+7; gives an error message because the assignment operator (=) is used inside the parentheses. The assignment operator is not allowed in an expression because it does not return a value. Therefore, the expression is not valid and cannot be evaluated.