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
how to print electricity bill according to following charges first 100 units -1rs per unit for next 200 units-1.50 rs per unit without using conditions
What is int main () in c?
What is the Purpose of 'extern' keyword in a function declaration?
Is fortran still used today?
How can you convert integers to binary or hexadecimal?
Tell me when would you use a pointer to a function?
What is difference between structure and union in c programming?
Can I use base-2 constants (something like 0b101010)? Is there a printf format for binary?
What is gets() function?
What is the difference between procedural and functional programming?
Find MAXIMUM of three distinct integers using a single C statement
Can we assign integer value to char in c?
What is the difference between %d and %i?
How can you check to see whether a symbol is defined?
What is wild pointer in c with example?