C Programming :: Dynamic Memory Allocation - Discussion
Home > C Programming > Dynamic Memory Allocation > MCQs Questions Discussion
4 / 18
What is the output of the following 'C' program ?
#define MAX 50
int fun1()
{
char *s1;
s1=(char *) malloc (MAX*sizeof(char));
s1="hello";
printf("%d",s1);
free(s1);
}
int fun2()
{
char *s;
s=(char *) malloc (MAX*sizeof(char));
strcpy(s,"hello");
printf("%d",s);
free(s);
}
int main ()
{
fun1();
fun2();
return 0;
}
#define MAX 50
int fun1()
{
char *s1;
s1=(char *) malloc (MAX*sizeof(char));
s1="hello";
printf("%d",s1);
free(s1);
}
int fun2()
{
char *s;
s=(char *) malloc (MAX*sizeof(char));
strcpy(s,"hello");
printf("%d",s);
free(s);
}
int main ()
{
fun1();
fun2();
return 0;
}
ACompilation Error
Bhello hello
CSegmentation fault
Dhello Segmentation fault
Answer: Option (Login/Signup)
Show Explanation
Asked In ::
No Discussion on this question yet!