Professional Documents
Culture Documents
struct node
{
int i;
float j;
};
struct node *s[10] ;
define s to be
(A) An array, each element of which is a pointer to a structure of type node
(B) A structure of 2 fields, each field being a pointer to an array of 10 elements
(C) A structure of 3 fields: an integer, a float, and an array of 10 elements
(D) An array, each element of which is a structure of type node.
Answer: (A)
Explanation:
// The following code declares a structure
struct node
{
int i;
float j;
};
Answer: (B)
Explanation: Initialisation: x = 1, i = 1;
Loop: x i
21 2
22 3
24 4
216 5
After this condition becomes false.
So, i = 5, Option (B) is correct.
Study the following program:
//precondition: x>=0
public void demo(int x)
{
System.out.print(x % 10);
if (x % 10 != 0)
{
demo(x/10);
}
System.out.print(x%10);
}
Which of the following is printed as a result of the call demo(1234)?
(A) 1441
(B) 3443
(C) 12344321
(D) 43211234
Answer: (D)
Explanation: In the above code, first print statement is executed and prints the value obtained after
performing modulus of 10 and the recursively another function is called with the value divide by 10. And
after the return of the function, it prints the values again.
demo(1234)
prints 4 call demo(123)
prints 3 call demo(12)
prints 2 call demo(1)
prints 1 call demo (0)
prints 1 prints 2 prints 3 prints 4.
So, option (D) is correct.