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 / smirnov_amm
It will show "HELL"
the f function reserve only 4 bytes with the sizeof(6). it will return the sizeof (int) =4 bytes.
So you only allocate 4 bytes.
When performing the strcpy, you will corupt memory because you'll copy more than allocate.
Cheers
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
What is the size of array float a(10)?
Is c easy to learn?
How do we print only part of a string in c?
What is the difference between union and structure in c?
what are # pragma staments?
How was c created?
What are near, far and huge pointers?
Explain the binary height balanced tree?
What is the use of static variable in c?
#define MAX(x,y) (x) >(y)?(x):(y) main() { inti=10,j=5,k=0; k= MAX(i++,++j); printf("%d..%d..%d",i,j,k); }
Hello. How to write a C program to check and display president party like if i type in the console "biden" and hit enter the output shoud be : "biden is democrat" and if i type "trump" and hit enter the output shoud be: "trump is republican"
How can I implement sets or arrays of bits?
How is a null pointer different from a dangling pointer?
What is derived datatype in c?
Is fortran still used in 2018?