Mike Lundell wrote in news::
> Rob Williscroft wrote:
>
>> char[16]
>
> is that like a new instance of the "char" class defined as char *c?
char my_array[16]; // an array of 16 char's
char *p = my_array;
p 'points to' the first element of 'my_array'.
in C++ you can reference the array's elements like this:
char c = my_array[ n ]; // where 0 <= n and n < 16.
C++ allows you to do the same with pointers (i.e 'p' above):
char c2 = p[ n ];
If you want to have an array that lives longer than the function
you create it in then you can write:
char *dynamic_p = new char[16];
dynamic_p now 'points to' an (unnamed if you like) array that the
compiler has created. To get rid of the array, once you're finnished
with it, write:
delete [] dynamic_p;
>
> if so, i'm guessing the 16 is for how many characters are defined for
> that var. (much like in mySQL). Anyway, this is all guessing on that
> part. but that does makes sense to me if that's what it is. I haven't
> started my college course yet, so that's why I don't know this stuff,
If you want a head start before you start your course I'd suggest
getting a book, maybe one you're going to have to get for course
anyway, It'll be a lot faster than trying to learn via usenet.
> i'm sure. But, one more question.. what does the "*" do to the "c"?
It changes the type of the variable being declared.
char c; // in words: c is of type char.
char *p; // in words: p is of type pointer to char.
> I'm guessing, it's some sort of alias pointer.. but even if that's
> what it is. It makes no sense to me, why you would need an "alias" if
> the letter c was the variable name?!.. I'm really confused on that
> part. And I know this isn't good, my first language I learned was vb
> (don't tell anyone that lol, i'm rather embarased). And, so, now it's
> kind of hard to accept the way new languages do things, especially
> when i've never seen it before. could someone clarify what exactly
> the "*" does please? thank you in advanced.
This post hasn't covered 1% of "what exactly the "*" does", so get
a good book and go to that course.
HTH
Rob.
--
http://www.victim-prime.dsl.pipex.com/