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 should malloc(0) do?

802


What is a void pointer in c?

823


What is the meaning of c in c language?

802


What are reserved words with a programming language?

823


How many types of functions are there in c?

781


process by which one bit patten in to another by bit wise operation is? (a) masking, (b) pruning, (c) biting, (d) chopping,

2133


Why does not c have an exponentiation operator?

798


What is a memory leak? How to avoid it?

865


Why cant I open a file by its explicit path?

802


Explain what is the difference between text files and binary files?

853


What are the different types of errors?

826


What is the purpose of & in scanf?

822


What is the difference between volatile and const volatile?

743


How can I open files mentioned on the command line, and parse option flags?

798


If one class contains another class as a member, in what order are the two class constructors called a) Constructor for the member class is called first b) Constructor for the member class is called second c) Only one of the constructors is called d) all of the above

821