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

The program will first compute the tax you owe based on your income. User is prompted to enter income. Program will compute the total amount of tax owed based on the following: Income Tax 0 - $45,000 = 0.15 x income $45,001 - $90,000 = 6750 + 0.20 x (income – 45000) $90,001 - $140,000 = 15750 + 0.26 x (income – 90000) $140,001 - $200,000 = 28750 + 0.29 x (income – 140000) Greater than $200,000 = 46150 + 0.33 x (income – 200000) Dollar amounts should be in dollars and cents (float point numbers with two decimals shown). Tax is displayed on the screen.

1290


Explain what is a const pointer?

833


Why pointers are used in c?

753


Write a program to check prime number in c programming?

811


write a program to convert a expression in polish notation(postfix) to inline(normal) something like make 723+* (2+3) x 7 (not sure) just check out its mainly printing expression in postfix form to infix.

3731


What is static volatile in c?

749


How does normalization of huge pointer works?

874


What is the difference between the = symbol and == symbol?

818


Write programs for String Reversal & Palindrome check

792


When is a null pointer used?

827


a c variable cannot start with a) an alphabet b) a number c) a special symbol d) both b and c above

982


What is cohesion and coupling in c?

794


write a c program in such a way that if we enter the today date the output should be next day's date.

1905


How do I round numbers?

783


What does *p++ do? What does it point to?

811