Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C - C++ Learning > malloc and new....
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 4 Topic 4132 of 4217
Post > Topic >>

malloc and new. I am not 100% sure which is proper

by Firkraag <firkraag07@[EMAIL PROTECTED] > May 1, 2008 at 02:15 AM

Here is the malloc version:

unsigned char **kolor;
kolor = (unsigned char**)malloc(10 * sizeof(char*));

Now I am not exactly sure which version using new means the same as
the one using malloc:

1. unsigned char** kolor = new unsigned char* [10];
2. unsigned char* kol0 = new unsigned char [10];
    unsigned char** kolor = &kol0;

Somebody told me, that the first version, because malloc allocates 10
unsigned char*s here. Okay, but what if we used sizeof(char) instead?
Something is fishy here. BTW the type "unsigned char" is just an
example.
 




 4 Posts in Topic:
malloc and new. I am not 100% sure which is proper
Firkraag <firkraag07@[  2008-05-01 02:15:27 
Re: malloc and new. I am not 100% sure which is proper
Francis Glassborow <fr  2008-05-01 11:22:11 
Re: malloc and new. I am not 100% sure which is proper
Firkraag <firkraag07@[  2008-05-01 12:30:47 
Re: malloc and new. I am not 100% sure which is proper
Jerry Coffin <jcoffin@  2008-05-03 10:55:07 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Thu Jul 24 13:22:10 CDT 2008.