1. What is the output of this C code?
-
#include <stdio.h>
-
int main()
-
{
-
char *p[1] = {"hello"};
-
printf("%s", (p)[0]);
-
return 0;
-
}
a) Compile time error
b) Undefined behaviour
c) hello
d) None of the mentioned
Answer
Answer: c [Reason:] None.
2. What is the output of this C code?
-
#include <stdio.h>
-
int main()
-
{
-
char **p = {"hello", "hi", "bye"};
-
printf("%s", (p)[0]);
-
return 0;
-
}
a) Compile time error
b) Undefined behaviour
c) hello
d) Address of hello
Answer
Answer: b [Reason:] None.
3. What is the output of this C code?
-
#include <stdio.h>
-
int main()
-
{
-
int i = 0, j = 1;
-
int *a[] = {&i, &j};
-
printf("%d", (*a)[0]);
-
return 0;
-
}
a) Compile time error
b) Undefined behaviour
c) 0
d) Some garbage value
Answer
Answer: c [Reason:] None.
4. What is the output of this C code?
-
#include <stdio.h>
-
int main()
-
{
-
int i = 0, j = 1;
-
int *a[] = {&i, &j};
-
printf("%d", *a[0]);
-
return 0;
-
}
a) Compile time error
b) Undefined behaviour
c) 0
d) Some garbage value
Answer
Answer: c [Reason:] None.
5. What is the output of this C code?
-
#include <stdio.h>
-
int main()
-
{
-
int i = 0, j = 1;
-
int *a[] = {&i, &j};
-
printf("%d", (*a)[1]);
-
return 0;
-
}
a) Compile time error
b) Undefined behaviour
c) 1
d) Some garbage value
Answer
Answer: d [Reason:] None.
6. Which of the following are generated from char pointer?
a) char *string = “Hello.”;
b) char *string;
scanf(“%s”, string);
c) char string[] = “Hello.”;
d) char *string = “Hello.”; and char string[] = “Hello.”;
Answer
Answer: a [Reason:] None.
7. Which of the following declaration are illegal?
a) int a[][] = {{1, 2, 3}, {2, 3, 4, 5}};
b) int *a[] = {{1, 2, 3}, {2, 3, 4, 5}};
c) int a[4][4] = {{1, 2, 3}, {2, 3, 4, 5}};
d) none of the mentioned
Answer
Answer: a [Reason:] None.