954,504 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

malloc() memory allocation and initialisation

char* p=(char*)malloc(10);
in the above state ment,has the memory been initialised??...what is the difference between allocatingg it and initialising it??
thanks in avdance...

IndianaRonaldo
Light Poster
39 posts since Jan 2011
Reputation Points: 7
Solved Threads: 1
 

Quote from cpp reference:

'Allocates a block of size bytes of memory, returning a pointer to the beginning of the block.

The content of the newly allocated block of memory is not initialized, remaining with indeterminate values.'

Insensus
Junior Poster
112 posts since Mar 2011
Reputation Points: 70
Solved Threads: 46
 

1. Allocation means to create space for your application use
2. Initialize means to assign specific values to that space

Using malloc creates space, but contents of space undefined

template<>
Junior Poster
165 posts since Feb 2011
Reputation Points: 84
Solved Threads: 26
 

thanks a lot guys...:)..it helped...

IndianaRonaldo
Light Poster
39 posts since Jan 2011
Reputation Points: 7
Solved Threads: 1
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: