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 / shruti

The output would be "HELLO"..

though we are not returning the string, we are making
direct changes at the memory location..

so "bye" will be overwritten with "HELLO"


because we are using pointers, the dying pointer scenario
is not applicabe here..

Its a pointer, not a variable..


This function will work similar to -> swapping two numbers
using pointers..
juss check that prog if you fnd somewhere.. :-)
you will get the logic... :-)


Cheers...


--By the way a gud ques.. :-)

Is This Answer Correct ?    1 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Write a program to check armstrong number in c?

631


What is meant by operator precedence?

668


What are loops in c?

545


Synonymous with pointer array a) character array b) ragged array c) multiple array d) none

611


How a string is stored in c?

580






Do array subscripts always start with zero?

776


Do character constants represent numerical values?

834


How many types of errors are there in c language? Explain

565


Can include files be nested? How many levels deep can include files be nested?

651


#include main() { enum _tag{ left=10, right, front=100, back}; printf("left is %d, right is %d, front is %d, back is %d",left,right,front,back); }

708


What is meant by inheritance?

625


How can I get back to the interactive keyboard if stdin is redirected?

663


Differentiate between functions getch() and getche().

616


What is the general form of a C program?

594


develop algorithms to add polynomials (i) in one variable

1731