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
Explain the use of #pragma exit?
Write a program to display all the prime nos from 1 to 1000000, your code should not take time more than a minute to display all the nos.
To print the pattern 1 2 3 4 5 10 17 18 19 6 15 24 25 20 7 14 23 22 21 8 13 12 11 10 9
Is linux written in c?
What is structure pointer in c?
How can you return multiple values from a function?
what is the different bitween abap and abap-hr?
FILE *fp1,*fp2; fp1=fopen("one","w") fp2=fopen("one","w") fputc('A',fp1) fputc('B',fp2) fclose(fp1) fclose(fp2)} a.error b. c. d.
Here is a good puzzle: how do you write a program which produces its own source code as output?
Can you please explain the difference between syntax vs logical error?
What is sizeof int?
What is the difference between a function and a method in c?
What is difference between && and & in c?
How do you initialize pointer variables?
What are the features of c languages?