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
Write a program to check armstrong number in c?
What is meant by operator precedence?
What are loops in c?
Synonymous with pointer array a) character array b) ragged array c) multiple array d) none
How a string is stored in c?
Do array subscripts always start with zero?
Do character constants represent numerical values?
How many types of errors are there in c language? Explain
Can include files be nested? How many levels deep can include files be nested?
#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); }
What is meant by inheritance?
How can I get back to the interactive keyboard if stdin is redirected?
Differentiate between functions getch() and getche().
What is the general form of a C program?
develop algorithms to add polynomials (i) in one variable