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


Please Help Members By Posting Answers For Below Questions

Explain the properties of union.

619


Can a variable be both constant and volatile?

572


Write a program, where i have a grid with many cells, how many paths are possible from one point to other desired points.

715


What extern c means?

551


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?

790






what do the 'c' and 'v' in argc and argv stand for?

656


What is the difference between mpi and openmp?

746


Where is volatile variable stored?

657


How can you restore a redirected standard stream?

621


What is multidimensional arrays

639


How to draw the flowchart for structure programs?

8768


When should we use pointers in a c program?

643


formula to convert 2500mmh2o into m3/hr

509


What is the difference between if else and switchstatement

1325


What is c value paradox explain?

588