Member Avatar for I_m_rude

Can i allocate memory to an array of it or char using malloc ? if yes, then why is it so ? And if no then also why ? I am confused a little bit. thanks in advance to james sir ;)

Yes, you can use malloc() to allocate a simulated array of int or char. What were you trying to do that prompted this question?

Member Avatar for I_m_rude

no, what i am tryong to ask is that if there is an array of

char s[100]={0};


s=malloc(sizeof(char)*20);

is it valid to do so ? But why is it valid ? because s is an array already.

is it valid to do so ?

No, it's not valid. Arrays are not pointers, they're arrays. You can use malloc() and a pointer to fake an array, but it's not natively an array. Likewise, in many cases an array will be converted into a pointer, but it's not natively a pointer.

Member Avatar for I_m_rude

but in initial post, u said u can so ? why ?

but in initial post, u said u can so ? why ?

Obviously I didn't understand your question.

Member Avatar for I_m_rude

:'( sir, if i allocate memory to a pointer and make it an array , then is it now an array ? means it is just same like an array ?

if i allocate memory to a pointer and make it an array , then is it now an array ?

No, but it can largely be used to simulate an array.

Member Avatar for I_m_rude

what simulate means here ?

It's a fake. It acts like an array for the most part, but isn't an array. Have you considered looking up the definition of "simulate"? That's exactly what it means here.

Member Avatar for I_m_rude

Can you reply on my thread "request to daniweb members" ? it's a request. If you ill do, that will motivate others. thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.