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 use of null pointer in c?
Is c is a middle level language?
What does c mean before a date?
How would you rename a function in C?
How do I convert a string to all upper or lower case?
What are valid signatures for the Main function?
disply the following menu 1.Disply 2.Copy 3.Append; as per the menu do the file operations 4.Exit
Tell me can the size of an array be declared at runtime?
How would you obtain the current time and difference between two times?
Where register variables are stored in c?
Why we use break in c?
What is the most efficient way to count the number of bits which are set in an integer?
what are the advantages of a macro over a function?
Where static variables are stored in c?
What is string concatenation in c?