-
What will be the output of the following C code?
#include <stdio.h>
int main()
{
struct S
{
char *name;
struct S *next;
};
struct S s1, s2;
s1.name = "Ajit Kumar Gupta";
s1.next = NULL;
ptrary[0] = &s1;
strcpy(s2.name, s1.name);
ptrary[1] = &s2;
printf("%s\n", ptrary[1]->name);
return 0;
}
-
- Garbage value
- Compilation Error
- Ajit Kumar Gupta
- Undefined behaviour
- None of these
Correct Option: B
Compilation Error
main.c: In function ‘main’:
main.c:12:9: error: ‘ptrary’ undeclared (first use in this function)
ptrary[0] = &s1;
^~~~~~
main.c:12:9: note: each undeclared identifier is reported only once for each function it appears in
main.c:13:9: warning: implicit declaration of function ‘strcpy’ [-Wimplicit-function-declaration]
strcpy(s2.name, s1.name);
^~~~~~
main.c:13:9: warning: incompatible implicit declaration of built-in function ‘strcpy’
main.c:13:9: note: include ‘’ or provide a declaration of ‘strcpy’