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
Explain what are multibyte characters?
What is the difference between array and pointer?
WHAT IS THE DEFINATION OF IN TECHNOLOGY AND OFF TECHNOLOGY ?
Can the size of an array be declared at runtime?
Which is an example of a structural homology?
Is it possible to use curly brackets ({}) to enclose single line code in c program?
What is 'bus error'?
What is the function of volatile in c language?
What are structural members?
Simplify the program segment if X = B then C ← true else C ← false
Explain what is the stack?
Explain can static variables be declared in a header file?
There is a practice in coding to keep some code blocks in comment symbols than delete it when debugging. How this affect when debugging?
Function which gives a pointer to a binary trees const an integer value at each code, return function of all the nodes in binary tree.?
Is c++ based on c?