1. What is the output of this C code (considering sizeof char is 1 and pointer is 4)?
-
#include <stdio.h>
-
int main()
-
{
-
char *a[2] = {"hello", "hi"};
-
printf("%d", sizeof(a));
-
return 0;
-
}
a) 9
b) 4
c) 8
d) 10
Answer
Answer: c [Reason:] None.
2. What is the output of this C code?
-
#include <stdio.h>
-
int main()
-
{
-
char a[2][6] = {"hello", "hi"};
-
printf("%d", sizeof(a));
-
return 0;
-
}
a) 9
b) 12
c) 8
d) 10
Answer
Answer: b [Reason:] None.
3. What is the output of this C code?
-
#include <stdio.h>
-
int main()
-
{
-
char a[2][6] = {"hello", "hi"};
-
printf("%s", *a + 1);
-
return 0;
-
}
a) hello
b) hi
c) ello
d) ello hi
Answer
Answer: c [Reason:] None.
4. What is the output of this C code?
-
#include <stdio.h>
-
int main()
-
{
-
char *a[2] = {"hello", "hi"};
-
printf("%s", *(a + 1));
-
return 0;
-
}
a) hello
b) ello
c) hi
d) ello hi
Answer
Answer: c [Reason:] None.
5. Advantage of a multi-dimension array over pointer array.
a) Pre-defined size.
b) Input can be taken from user.
c) Faster Access.
d) All of the mentioned
Answer
Answer: d [Reason:] None.
6. Which of the following operation is possible using a pointer char?
(Assuming declaration char *a;)
a) Input via %s
b) Generation of multidimensional array
c) Changing address to point at another location
d) All of the mentioned
Answer
Answer: c [Reason:] None.
7. Comment on the following two operations?
int *a[] = {{1, 2, 3}, {1, 2, 3, 4}}; //- 1
int b[4][4] = {{1, 2, 3}, {1, 2, 3, 4}};//- 2
a) 1 will work, 2 will not
b) 1 and 2, both will work
c) 1 won’t work, 2 will work
d) Neither of them will work
Answer
Answer: c [Reason:] None.
8. Comment on the following two operations?
int *a[] = {{1, 2, 3}, {1, 2, 3, 4}}; //- 1
int b[][] = {{1, 2, 3}, {1, 2, 3, 4}}; //- 2
a) 1 works, 2 doesn’t
b) 2 works, 1 doesn’t
c) Both of them work
d) Neither of them work
Answer
Answer: d [Reason:] None.