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 are the types of data structures in c?
what will be the output for the following main() { printf("hi" "hello"); }
Who is the founder of c language?
How can I swap two values without using a temporary?
Why c is a mother language?
What is build process in c?
can any one provide me the notes of data structure for ignou cs-62 paper
What is the meaning of ?
What is data types?
What are structures and unions? State differencves between them.
Why is python slower than c?
What is the sizeof () a pointer?
What is typedf?
Explain what is a static function?
Which programming language is best for getting job 2020?