questions about asterix and global vars

1st question:
I am on the lesson about structures and am having a prob understanding something:
this is a simple prog using an array of struct.
The struct is declared as well as a var of that type: invtry[SIZE]
main() calls different funct one of which i have a prob understanding:

//this funct initializes the array
void init_list()
{
int t;
for (t = 0; t<SIZE; t++) *invtry[t].item = '\0';
}

I don't understand *invtry[t]..... the asterix throws me off


2nd question:

In this same program at the beginning you have the statement:

const int SIZE = 100;

could i replace that with:

#define SIZE 100

what is the difference??
Last edited on
1st question:

The * is dereferencing a pointer:

http://www.cplusplus.com/doc/tutorial/pointers/

2nd question:

const int SIZE = 100; defines a global const that can accessed from anywhere in the program.

#define SIZE 100 is defining a macro that will be interpreted by the preprocessor:

http://www.cplusplus.com/doc/tutorial/preprocessor/

There's not a whole lot of difference between them in terms of how you use them in your program. Both are not very nice, as they undermine the concept of encapsulation, but when the heat is on, they have their uses.
Topic archived. No new replies allowed.