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 / yathish m yadav
the output is "hello".
here we are overwriting pointer *p thrice.
that is in the function we get an piece of memory from
malloc and assigned to p,
in the statement strcpy(p,"hello");
the malloc memory is lost and the compiler creates an char
array and copies the string "hello" and it makes the
character array as constant.
| Is This Answer Correct ? | 0 Yes | 2 No |
Post New Answer View All Answers
What is the function of this pointer?
Find duplicates in a file containing 6 digit number (like uid) in O (n) time.
How to get string length of given string in c?
What’s the special use of UNIONS?
Hai what is the different types of versions and their differences
Write a program to print fibonacci series using recursion?
What are the types of pointers?
Why are all header files not declared in every c program?
How do I use strcmp?
How many bytes are occupied by near, far and huge pointers (dos)?
what is the structure pointer?
What is merge sort in c?
Explain what is the benefit of using #define to declare a constant?
Explain about C function prototype?
What is an auto variable in c?