-
What will be the output of the following C code?
#include <stdio.h>
struct B
{
char *name;
struct B *next;
};
struct B *ptrary[10];
int main()
{
struct B b;
b->name = "Raj";
b->next = NULL;
ptrary[0] = &b;
printf("%s\n", b->name);
return 0;
}
-
- Compilation Error
- Raj
- Garbage value
- Undefined behaviour
- None of these
Correct Option: A
Compilation Error
main.c: In function ‘main’:
main.c:11:10: error: invalid type argument of ‘->’ (have ‘struct B’)
b->name = "Raj";
^~
main.c:12:10: error: invalid type argument of ‘->’ (have ‘struct B’)
b->next = NULL;
^~
main.c:14:25: error: invalid type argument of ‘->’ (have ‘struct B’)
printf("%s\n", b->name);