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 / yathish m yadav
the output is "hello".
here we are overwriting pointer *p thrice.
that is in the function we get an piece of memory from
malloc and assigned to p,
in the statement strcpy(p,"hello");
the malloc memory is lost and the compiler creates an char
array and copies the string "hello" and it makes the
character array as constant.
| Is This Answer Correct ? | 0 Yes | 2 No |
Post New Answer View All Answers
What is the best style for code layout in c?
Explain the properties of union. What is the size of a union variable
Do you know the difference between malloc() and calloc() function?
int i[2], j; int *pi;i[0] = 1; i[1] = 5; pi = i; j = *pi + 1 + *(pi + 1)Value of j after execution of the above statements will be a) 7 b) 6 c) 4 d) pointer
Which type of language is c?
what is the height of tree if leaf node is at level 3. please explain
List the difference between a 'copy constructor' and a 'assignment operator' in C?
#define MAX(x,y) (x) >(y)?(x):(y) main() { inti=10,j=5,k=0; k= MAX(i++,++j); printf("%d..%d..%d",i,j,k); }
why use functions a) writing functions avoids rewriting the same code over and over b) using functions it becomes easier to write programs and keep track of what they are doing c) a & b d) none of the above
What does %d do in c?
which is an algorithm for sorting in a growing Lexicographic order
Why do we use namespace feature?
PROGRAM TO WRITE CONTENTS OF 1 FILE IN REVERSE TO ANOTHER FILE,PROGRAM TO COPY 1 FILE TO ANOTHER BY SPECIFYING FILE NAMES AS COMMAND LINE
Explain what is the difference between a string and an array?
Tell me can the size of an array be declared at runtime?