Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

What is the best style for code layout in c?

1148


Explain the properties of union. What is the size of a union variable

1248


Do you know the difference between malloc() and calloc() function?

1112


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

1098


Which type of language is c?

1126


what is the height of tree if leaf node is at level 3. please explain

2204


List the difference between a 'copy constructor' and a 'assignment operator' in C?

1144


#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); }

1212


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

1208


What does %d do in c?

1014


which is an algorithm for sorting in a growing Lexicographic order

1868


Why do we use namespace feature?

1121


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

2090


Explain what is the difference between a string and an array?

1229


Tell me can the size of an array be declared at runtime?

1086