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

Why is structure important for a child?

595


How can I convert a number to a string?

596


What is #line used for?

568


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.

2643


explain what are pointers?

610






What should malloc(0) do? Return a null pointer or a pointer to 0 bytes?

576


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

1892


Write a program in c to replace any vowel in a string with z?

680


How can I find out if there are characters available for reading?

631


What is the size of empty structure in c?

579


Is python a c language?

542


What are loops c?

604


can we implement multi-threads in c.

653


Is boolean a datatype in c?

535


What are the ways to a null pointer can use in c programming language?

581