Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

What is a void * in c?

1040


Was 2000 a leap year?

1014


What does typedef struct mean?

1064


What is file in c language?

976


What is the advantage of an array over individual variables?

1200


Is there a built-in function in C that can be used for sorting data?

1200


What is this infamous null pointer, anyway?

1003


What is else if ladder?

982


What is the use of header?

1069


What do the functions atoi(), itoa() and gcvt() do?

1153


What is boolean in c?

1052


List the difference between a While & Do While loops?

1064


What are enumerated types?

1133


Explain the bubble sort algorithm.

1014


What is difference between function overloading and operator overloading?

1062