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
Can we declare variable anywhere in c?
how is the examination pattern?
What are the application of void data type in c?
In a switch statement, explain what will happen if a break statement is omitted?
If a variable is a pointer to a structure, then which operator is used to access data members of the structure through the pointer variable?
What are the different types of endless loops?
differentiate built-in functions and user – defined functions.
What are the main characteristics of c language describe the structure of ac program?
What is #include stdio h and #include conio h?
What is pointer and structure in c?
What are compound statements?
A collection of data with a given structure for excepting storing and providing on demand data for multiple users a) linked list b) datastructer c) database d) preprocessor
What are different types of pointers?
How can I open a file so that other programs can update it at the same time?
Can you please explain the scope of static variables?