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
Why is structure important for a child?
How can I convert a number to a string?
What is #line used for?
Explain with the aid of an example why arrays of structures don’t provide an efficient representation when it comes to adding and deleting records internal to the array.
explain what are pointers?
What should malloc(0) do? Return a null pointer or a pointer to 0 bytes?
the real constant in c can be expressed in which of the following forms a) fractional form only b) exponential form only c) ascii form only d) both a and b
Write a program in c to replace any vowel in a string with z?
How can I find out if there are characters available for reading?
What is the size of empty structure in c?
Is python a c language?
What are loops c?
can we implement multi-threads in c.
Is boolean a datatype in c?
What are the ways to a null pointer can use in c programming language?