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

The output would be "HELLO"..

though we are not returning the string, we are making
direct changes at the memory location..

so "bye" will be overwritten with "HELLO"


because we are using pointers, the dying pointer scenario
is not applicabe here..

Its a pointer, not a variable..


This function will work similar to -> swapping two numbers
using pointers..
juss check that prog if you fnd somewhere.. :-)
you will get the logic... :-)


Cheers...


--By the way a gud ques.. :-)

Is This Answer Correct ?    1 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is function in c with example?

617


Why pointers are used?

623


What is the description for syntax errors?

602


What are different types of pointers?

550


given post order,in order construct the corresponding binary tree

2310






Is c dynamically typed?

659


What are structures and unions? State differencves between them.

600


What is #include in c?

587


What are the 4 types of organizational structures?

611


How can I use a preprocessorif expression to ?

592


What does %c do in c?

578


Why c is called free form language?

557


What is the purpose of 'register' keyword in c language?

610


What is define directive?

627


What is the size of structure in c?

689