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 a ternary operator in c?
What are the different types of linkage exist in c?
what does static variable mean?
what is the c source code for the below output? 5555555555 4444 4444 333 333 22 22 1 1 22 22 333 333 4444 4444 5555555555
How will you delete a node in DLL?
What is difference between structure and union with example?
Does c have class?
What is difference between stdio h and conio h?
write a program to find the given number is prime or not
What is a function simple definition?
what are the advantages of a macro over a function?
Input is "rama loves rajesh and rajesh Loves rama also and rajesh wear gloves and bloves" To print output is count the numbers of times repeted the word love without case sensitive.
What are global variables and how do you declare them?
general for is %wd,f-d; in this system "w" means a) 'w' represent total width of digits b) 'w' represent width which includes the digits before,after decimal place and the decimal point c) 'w' represent width which includes the digits before only d) 'w' represent width after decimal place only
Describe how arrays can be passed to a user defined function