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 is function in c with example?
Why pointers are used?
What is the description for syntax errors?
What are different types of pointers?
given post order,in order construct the corresponding binary tree
Is c dynamically typed?
What are structures and unions? State differencves between them.
What is #include in c?
What are the 4 types of organizational structures?
How can I use a preprocessorif expression to ?
What does %c do in c?
Why c is called free form language?
What is the purpose of 'register' keyword in c language?
What is define directive?
What is the size of structure in c?