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

Answers were Sorted based on User's Feedback



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

Answer / shruti

the syntax of malloc is wrong.

in your example it should be written as:

char *p;

p = (char *)malloc(sizeof(char));

Is This Answer Correct ?    21 Yes 1 No

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

Answer / guest

The pointer you declared is p, not *p.

Is This Answer Correct ?    10 Yes 0 No

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

Answer / parasher

char *p;

p = (char *)malloc(sizeof(char));

Is This Answer Correct ?    8 Yes 2 No

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

Answer / raj

here syntox of malloc is not fallowed

Is This Answer Correct ?    3 Yes 1 No

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

Answer / clay

Here,

After char *p;
since pointer p is not initialized it is pointing at some
unknown location.

In the next step, the address of the memory allocated by
malloc() is stored at some garbage location pointed by p.

Here p is never initialized or never assigned any value.

Is This Answer Correct ?    0 Yes 3 No

Post New Answer

More C Interview Questions

what are the advantages & disadvantages of unions?

2 Answers  


How can I make it pause before closing the program output window?

0 Answers  


What is wrong with this code?

0 Answers  


2.Given the short c program that follows a. make a list of the memory variables in this program b.which lines of code contain operations that change the contents of memory? what are those operations? Void main( void) { Double base; Double height; Double area; Printf(“enter base and height of triangle :”); Scanf(“%lg”, &base); Scanf(“%lg”, &height); Area=base*height/2.0; Printf(“the area of the triangle is %g \n”,area); }

1 Answers   Wipro,


What is c language used for?

0 Answers  






in ‘C’ language for Matrix Multiplication fails” Introspect the causes for its failure and write down the possible reasons for its failure.

0 Answers   TCS,


How do you define a function?

0 Answers  


What is the difference b/w Structure & Union?

3 Answers  


What is hungarian notation? Is it worthwhile?

0 Answers  


main() { int i = 1; int num[] = {1,2,3,4}; num[i] = i++; printf("%d", num[i]); } what will be the output? }

22 Answers   NDS, TCS,


hi, which software companys will take,if d candidate's % is jst 55%?

0 Answers  


There are 8 billiard balls, and one of them is slightly heavier, but the only way to tell was by putting it on a weighing scale against another. What's the fewest number of times you'd have to use the scale to find the heavier ball?

5 Answers   Microsoft, TCS,


Categories