Question 1
#include \"stdio.h\"
int main()
{
struct {int a[2];} arr[] = {{1},{2}};
printf(\"%d %d %d %d\",arr[0].a[0],arr[0].a[1],arr[1].a[0],arr[1].a[1]);
return 0;
}
Question 2
#include \"stdio.h\"
int main()
{
struct {int a[2], b;} arr[] = {[0].a = {1}, [1].a = {2}, [0].b = 1, [1].b = 2};
printf(\"%d %d %d and\",arr[0].a[0],arr[0].a[1],arr[0].b);
printf(\"%d %d %d\\n\",arr[1].a[0],arr[1].a[1],arr[1].b);
return 0;
}
Question 3
Pick the best statement for the below program:
#include <stdio.h>
int main()
{
struct {
int i;
char c;
} myVar = {.i = 100, .c = 'A'};
printf("%d %c", myVar.i, myVar.c);
return 0;
}
Question 4
Pick the best statement for the below program:
#include <stdio.h>
int main()
{
union {
int i1;
int i2;
} myVar = {.i2 = 100};
printf("%d %d", myVar.i1, myVar.i2);
return 0;
}
Question 5
Consider the code fragment written in JAVA below :
void f (int n)
{
if (n <=1) {
System.out.print(n);
}
else {
f (n/2);
System.out.print(n%2);
}
}
What does f(173) print?
Question 6
Consider the code fragment written in C below :
void f (int n)
{
if (n <= 1) {
printf (\"%d\", n);
}
else {
f (n/2);
printf (\"%d\", n%2);
}
}
Which of the following implementations will produce the same output for f(173) as the above code? P1
void f (int n)
{
if (n/2) {
f(n/2);
}
printf (\"%d\", n%2);
}
P2
void f (int n)
{
if (n <=1) {
printf (\"%d\", n);
}
else {
printf (\"%d\", n%2);
f (n/2);
}
}
Question 7
Pick the best statement for the below program snippet:
struct {int a[2];} arr[] = {1,2};
There are 7 questions to complete.