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
Write a function stroverlap that takes (at least) two strings, and concatenates them, but does not duplicate any overlap. You only need to worry about overlaps between the end of the first string and the beginning of the second string. Examples: batman, manonthemoon = batmanonthemoon batmmamaman, mamamanonthemoon = batmmamamanonthemoon bat, man = batman batman, batman = batman batman, menonthemoon = batmanmenonthemoon
Why we use int main and void main?
What are control structures? What are the different types?
Explain what are header files and explain what are its uses in c programming?
What is unary operator?
What is c mainly used for?
What is use of #include in c?
What is pointers in c with example?
What does double pointer mean in c?
How can you draw circles in C?
What is c language used for?
How important is structure in life?
What is void main ()?
Tell us the use of fflush() function in c language?
What is an endless loop?