f(char *p)
{
p=(char *)malloc(sizeof(6));
strcpy(p,"HELLO");
}
main()
{
char *p="BYE";
f(p)
printf("%s",p);
}
what is the output?
Answer Posted / yathish m yadav
the output is "hello".
here we are overwriting pointer *p thrice.
that is in the function we get an piece of memory from
malloc and assigned to p,
in the statement strcpy(p,"hello");
the malloc memory is lost and the compiler creates an char
array and copies the string "hello" and it makes the
character array as constant.
| Is This Answer Correct ? | 0 Yes | 2 No |
Post New Answer View All Answers
What is a void * in c?
Was 2000 a leap year?
What does typedef struct mean?
What is file in c language?
What is the advantage of an array over individual variables?
Is there a built-in function in C that can be used for sorting data?
What is this infamous null pointer, anyway?
What is else if ladder?
What is the use of header?
What do the functions atoi(), itoa() and gcvt() do?
What is boolean in c?
List the difference between a While & Do While loops?
What are enumerated types?
Explain the bubble sort algorithm.
What is difference between function overloading and operator overloading?