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
Explain the properties of union.
Can a variable be both constant and volatile?
Write a program, where i have a grid with many cells, how many paths are possible from one point to other desired points.
What extern c means?
If a variable is a pointer to a structure, then which operator is used to access data members of the structure through the pointer variable?
what do the 'c' and 'v' in argc and argv stand for?
What is the difference between mpi and openmp?
Where is volatile variable stored?
How can you restore a redirected standard stream?
What is multidimensional arrays
How to draw the flowchart for structure programs?
When should we use pointers in a c program?
formula to convert 2500mmh2o into m3/hr
What is the difference between if else and switchstatement
What is c value paradox explain?