-
What will be the output of the following C code?
#include <stdio.h7gt;
struct City function(void)
{
struct City
{
char *name;
};
struct City c1;
c1.name = "Patna";
return c1;
}
void main()
{
struct City c2 = function();
printf("%s", c2.name);
}
-
- India
- Garbage value
- Undefined behaviour
- Compilation Error
- None of these
Correct Option: D
Compilation Error
main.c:2:17: error: return type is an incomplete type
struct City function(void)
^~~~~~~~
main.c: In function ‘function’:
main.c:10:16: warning: ‘return’ with a value, in function returning void
return c1;
^~
main.c:2:17: note: declared here
struct City function(void)
^~~~~~~~
main.c: In function ‘main’:
main.c:14:16: error: variable ‘c2’ has initializer but incomplete type
struct City c2 = function();
^~~~
main.c:14:21: error: storage size of ‘c2’ isn’t known
struct City c2 = function();