C Programming :: Dynamic Memory Allocation - Discussion
Home > C Programming > Dynamic Memory Allocation > MCQs Questions Discussion
3 / 18
What is the output of the following 'C' program ?
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct
{
char *name;
} Addr;
int main()
{
Addr *s;
char comm[10];
char *str = "Hello";
s = (Addr *)malloc(sizeof(Addr));
printf("Enter a name");
fgets(comm, 10,stdin);
s->name = (char*)malloc(sizeof(char[strlen(comm)]));
strcpy(s->name, comm);
strcat(str,s->name);
printf("%s", str);
}
// for the input: india
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct
{
char *name;
} Addr;
int main()
{
Addr *s;
char comm[10];
char *str = "Hello";
s = (Addr *)malloc(sizeof(Addr));
printf("Enter a name");
fgets(comm, 10,stdin);
s->name = (char*)malloc(sizeof(char[strlen(comm)]));
strcpy(s->name, comm);
strcat(str,s->name);
printf("%s", str);
}
// for the input: india
Aindia
BHello india
CSegmentation fault
DCompilation Error
ENone of these
Answer: Option (Login/Signup)
Show Explanation
Asked In ::
No Discussion on this question yet!