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
Why is struct padding needed?
What are the advantages of using new operator as compared to the function malloc ()?
Difference between malloc() and calloc() function?
What is the significance of c program algorithms?
What is #include called?
What is a constant?
How many identifiers are there in c?
Write a program to generate a pulse width frequency of your choise,which can be variable by using the digital port of your processor
Write a code of a general series where the next element is the sum of last k terms.
What is n in c?
how to introdu5ce my self in serco
Differentiate abs() function from fabs() function.
Explain the difference between call by value and call by reference in c language?
Explain can the sizeof operator be used to tell the size of an array passed to a function?
Is it cc or c in a letter?