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
Explain about the constants which help in debugging?
What are structures and unions? State differencves between them.
What is the size of enum in c?
What is variable initialization and why is it important?
What is clrscr ()?
Does c have class?
a linearly ordered set of data elements that have the same structure and whose order is preserved in storage by using sequential allocation a) circular b) ordinary c) array d) linear list
Can we increase size of array in c?
Is linux written in c?
What is enumerated data type in c?
What are the data types present in c?
Is a pointer a kind of array?
What is a newline escape sequence?
What are the different types of errors?
int i=3; this declaration tells the C compiler to a) reserve space in memory to hold the integer value b) associate the name i with this memory location c) store the value 3 at this location d) all the above