Two Basic Questions !

Hi.
I have 2 Basic Questions.
One. What's difference between these codes?
1. char ch;
2. char[1] ch1;
3. char* chptr = &ch;
I know which is pointer and which is a regular variable.

Two. What's difference between nesting two class and deriving a class from another?

Thanks
The first line initializes declares... a character. Indeed, I did mix up something, thanks filipe.
The second line is syntactically incorrect.
The third line creates a pointer to the memory the first character takes up.

As for the difference between inheritance and nesting... inheritance is a mechanism by which one can create a new class that extends and/or modifies a certain class's functionality and this AFAIK is always possible in C++. Nesting is when a class or struct is created in another in its definition, which may not always be possible.

Did I mess up my terminology?

-Albatross
Last edited on
Albatross wrote:
The first line initializes... a character.

That's a declaration, not an initialization. Initializing means attributing some value to the object.
Whoops. I knew I mixed something up. Thank you for that.

-Albatross
Thanks for answers but I should change the question
Changing line two with this:

2. char ch[1];

what is difference between this and 1 and 3 ?
thanks
excuse me for making mistake.
You meant for the array to be ch1[1], otherwise you have two variables with the same name.

Anyway,

1. Just a single plain character. Accessed with ch
2. An array with a size of one, its single value accessed with ch1[0]
3. A pointer to ch. It's value contains the memory address of ch. Accessed with chptr, and the data it points to is accessed with (*chptr) (parentheses () are optional)
Topic archived. No new replies allowed.