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

Can we declare variable anywhere in c?

526


how is the examination pattern?

1585


What are the application of void data type in c?

681


In a switch statement, explain what will happen if a break statement is omitted?

617


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?

768






What are the different types of endless loops?

608


differentiate built-in functions and user – defined functions.

609


What are the main characteristics of c language describe the structure of ac program?

604


What is #include stdio h and #include conio h?

588


What is pointer and structure in c?

556


What are compound statements?

618


A collection of data with a given structure for excepting storing and providing on demand data for multiple users a) linked list b) datastructer c) database d) preprocessor

616


What are different types of pointers?

552


How can I open a file so that other programs can update it at the same time?

648


Can you please explain the scope of static variables?

590