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

Explain what standard functions are available to manipulate strings?

0 Answers  


1.what are local and global variables? 2.what is the scope of static variables? 3.what is the difference between static and global variables? 4.what are volatile variables? 5.what is the use of 'auto' keyword? 6.how do we make a global variable accessible across files? Explain the extern keyword? 7.what is a function prototype? 8.what does keyword 'extern' mean in a function declaration?

2 Answers   nvidia,


Can i use “int” data type to store the value 32768? Why?

0 Answers  


What is calloc()?

0 Answers   Adobe,


Explain the difference between null pointer and void pointer.

0 Answers   TCS,






HOW TO SOLVE A NUMERICAL OF LRU IN OS ??????

0 Answers  


What is array in c with example?

0 Answers  


Explain union. What are its advantages?

0 Answers  


how can i include my own .h file EX:- alex.h like #include<alex.h>, rather than #include"alex.h"

1 Answers  


Can an array be an Ivalue?

0 Answers   EXL,


how to write a c program to print list of fruits in alpabetical order?

0 Answers  


Do string constants represent numerical values?

0 Answers  


Categories