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 / smirnov_amm

It will show "HELL"
the f function reserve only 4 bytes with the sizeof(6). it will return the sizeof (int) =4 bytes.
So you only allocate 4 bytes.
When performing the strcpy, you will corupt memory because you'll copy more than allocate.

Cheers

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Why is struct padding needed?

1160


What are the advantages of using new operator as compared to the function malloc ()?

1408


Difference between malloc() and calloc() function?

1271


What is the significance of c program algorithms?

1196


What is #include called?

1105


What is a constant?

1113


How many identifiers are there in c?

1086


Write a program to generate a pulse width frequency of your choise,which can be variable by using the digital port of your processor

3607


Write a code of a general series where the next element is the sum of last k terms.

1095


What is n in c?

1114


how to introdu5ce my self in serco

2049


Differentiate abs() function from fabs() function.

1073


Explain the difference between call by value and call by reference in c language?

1165


Explain can the sizeof operator be used to tell the size of an array passed to a function?

1118


Is it cc or c in a letter?

1081