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 %d used in c?
What is the role of this pointer?
Explain what is gets() function?
What is calloc() function?
What does %p mean?
What is the difference between ++a and a++?
write a program that reads lines(using getline), converts each line to an integer using atoi, and computes the average of all the numbers read. also compute the standard deviation.
Explain how can I make sure that my program is the only one accessing a file?
What functions are used in dynamic memory allocation in c?
What is the purpose of the preprocessor directive error?
Explain how do you list files in a directory?
hw can we delete an internal node of binary search tree the internal node has child node..plz write progarm
Once I have used freopen, how can I get the original stdout (or stdin) back?
What do you mean by scope of a variable in c?
Explain high-order bytes.