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


Please Help Members By Posting Answers For Below Questions

What is the use of in c?

564


Which built-in library function can be used to match a patter from the string?

729


What are valid signatures for the Main function?

694


If jack lies on Mon, Tue Wed and jill lies on Thursday, Friday and Saturday. If both together tell they lied yesterday. So c the given options and then c cos in the given dates one will be saying the truth and one will be lying. I got Thursday as option because jack is saying the truth he lied yest but jill is lying again as he lies on that day.

1775


What is volatile, register definition in C

676






a character or group of characters that defines a register,or a part of storage a) memory b) byte c) address d) linear list

617


Why can arithmetic operations not be performed on void pointers?

581


the constant value in the case label is followed by a a) semicolon b) colon c) braces d) none of the above

711


What do you mean by a sequential access file?

617


What is difference between constant pointer and constant variable?

614


What is action and transformation in spark?

579


Explain is it better to use a pointer to navigate an array of values, or is it better to use a subscripted array name?

659


Can a function be forced to be inline? Also, give a comparison between inline function and the C macro?

643


Is c pass by value or reference?

583


How does placing some code lines between the comment symbol help in debugging the code?

530