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 behavioral difference when include header file in double quotes (“”) and angular braces (<>)?
Multiply an Integer Number by 2 Without Using Multiplication Operator
Explain what is #line used for?
What are logical errors and how does it differ from syntax errors?
What is p in text message?
What are the string functions? List some string functions available in c.
Write a program to generate the Fibinocci Series
What is #define in c?
What does char * * argv mean in c?
What is the difference between strcpy() and memcpy() function in c programming?
What is scope rule of function in c?
What is mean by Data Driven framework in QTP? Can any one answer me in details on this regard.
What is static and auto variables in c?
What is a program flowchart and explain how does it help in writing a program?
Does free set pointer to null?