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

If the static variable is declared as global, will it be same as extern?

1 Answers   Samsung,


The file stdio.h, what does it contain?

0 Answers  


main difference between c and c++ language

1 Answers  


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

0 Answers   L&T,


How to swap 3 numbers without using 4th variable?

5 Answers  


What is c language & why it is used?

0 Answers  


which will return integer? a) int*s ( ) b) ( int* ) s( ) c) int ( *s ) ( )

1 Answers   C DAC,


What is break in c?

0 Answers  


Write a simple program to find the size of different basic data types in C.

3 Answers  


Explain with the aid of an example why arrays of structures don’t provide an efficient representation when it comes to adding and deleting records internal to the array.

0 Answers  


How does placing some code lines between the comment symbol help in debugging the code?

0 Answers  


What does dm mean sexually?

0 Answers  


Categories