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 use of in c?
Which built-in library function can be used to match a patter from the string?
What are valid signatures for the Main function?
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.
What is volatile, register definition in C
a character or group of characters that defines a register,or a part of storage a) memory b) byte c) address d) linear list
Why can arithmetic operations not be performed on void pointers?
the constant value in the case label is followed by a a) semicolon b) colon c) braces d) none of the above
What do you mean by a sequential access file?
What is difference between constant pointer and constant variable?
What is action and transformation in spark?
Explain is it better to use a pointer to navigate an array of values, or is it better to use a subscripted array name?
Can a function be forced to be inline? Also, give a comparison between inline function and the C macro?
Is c pass by value or reference?
How does placing some code lines between the comment symbol help in debugging the code?