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 the function of this pointer?

1453


Find duplicates in a file containing 6 digit number (like uid) in O (n) time.

3309


How to get string length of given string in c?

1121


What’s the special use of UNIONS?

1205


Hai what is the different types of versions and their differences

1975


Write a program to print fibonacci series using recursion?

1131


What are the types of pointers?

1188


Why are all header files not declared in every c program?

1148


How do I use strcmp?

1130


How many bytes are occupied by near, far and huge pointers (dos)?

1216


what is the structure pointer?

2178


What is merge sort in c?

1110


Explain what is the benefit of using #define to declare a constant?

1275


Explain about C function prototype?

1141


What is an auto variable in c?

1294