What's wrong with "char *p = malloc(10);" ?

Answer Posted / poornima

Nothing wrong.Its fine..
if u hve further doubt run the below code.

#include<stdio.h>
int main()
{
char *p=malloc(10);
if(p==NULL)
{
printf("malloc failed");
exit(0);
}
else
{
printf("malloc success\n");
p="hai";
printf("%s",p);
}
return 0;
}

o/p:
malloc success
hai

Is This Answer Correct ?    6 Yes 10 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

if the area was hit by a virus and so the decrease in the population because of death was x/3 and the migration from other places increased a population by 2x then annually it had so many ppl. find our the population in the starting.

4510


How can you invoke another program from within a C program?

620


What is the use of static variable in c?

597


What is the difference between c &c++?

649


What is a lookup table in c?

629






Is c easier than java?

578


Are pointers really faster than arrays?

569


What is the use of bitwise operator?

694


Which type of language is c?

656


what is associativity explain what is the precidence for * and & , * and ++ how the folloing declaration work 1) *&p; 2) *p++;

2009


What is integer constants?

626


Explain union.

641


Write a program to print numbers from 1 to 100 without using loop in c?

644


write a c program to calculate sum of digits till it reduces to a single digit using recursion

2725


we need to calculating INCOME TAX for the person. The INCOME TAX is as follows:- First $10000/- of income : 4% tax Next $10000/- of income : 8% tax Next $10000/- of income : 11.5% tax above $10, 00,00/- : 15% tax What is the Solution of this Question ?

805