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


Please Help Members By Posting Answers For Below Questions

the constant value in the case label is followed by a a) semicolon b) colon c) braces d) none of the above

717


What is #include called?

565


Where is volatile variable stored?

639


Write a program that takes a 5 digit number and calculates 2 power that number and prints it(should not use big integers and exponential functions)

5786


Explain indirection?

637






What is a static variable in c?

661


How to delete a node from linked list w/o using collectons?

2083


What extern c means?

529


What header files do I need in order to define the standard library functions I use?

535


What is a rvalue?

743


What is the difference between formatted&unformatted i/o functions?

610


Can you define which header file to include at compile time?

582


"%u" unsigned integer print the a) address of variable b) value of variable c) name of a variable d) none of the above

605


Is c procedural or functional?

582


What is a node in c?

543