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
What should malloc(0) do?
What is a void pointer in c?
What is the meaning of c in c language?
What are reserved words with a programming language?
How many types of functions are there in c?
process by which one bit patten in to another by bit wise operation is? (a) masking, (b) pruning, (c) biting, (d) chopping,
Why does not c have an exponentiation operator?
What is a memory leak? How to avoid it?
Why cant I open a file by its explicit path?
Explain what is the difference between text files and binary files?
What are the different types of errors?
What is the purpose of & in scanf?
What is the difference between volatile and const volatile?
How can I open files mentioned on the command line, and parse option flags?
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