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

how to print electricity bill according to following charges first 100 units -1rs per unit for next 200 units-1.50 rs per unit without using conditions

3129


What is int main () in c?

1028


What is the Purpose of 'extern' keyword in a function declaration?

1033


Is fortran still used today?

1041


How can you convert integers to binary or hexadecimal?

979


Tell me when would you use a pointer to a function?

1011


What is difference between structure and union in c programming?

1017


Can I use base-2 constants (something like 0b101010)? Is there a printf format for binary?

958


What is gets() function?

1074


What is the difference between procedural and functional programming?

1009


Find MAXIMUM of three distinct integers using a single C statement

1014


Can we assign integer value to char in c?

1157


What is the difference between %d and %i?

1043


How can you check to see whether a symbol is defined?

1048


What is wild pointer in c with example?

1020