views:

104

answers:

2

Suppose struct_name is the name of a struct I've defined, and array is a member in the struct defined as char array[o]

what does the following line produce? (*struct_name).array an address location?

+1  A: 

yes (assuming struct_name is a pointer to your struct, otherwise the dereferencing just doesn't make sense)

btw, why not do struct_name->array ?

246tNt
+1  A: 

If you've defined struct_name as an instance of your struct like this:

struct your_struct struct_name;

You want struct_name.array which, yes, produces an address to the array member. If you've defined struct_name as an instance of your struct like this:

struct your_struct *struct_name;
struct_name = malloc(sizeof(struct your_struct));

You want struct_name->array, which also returns the address of array.

If you've defined struct_name as the name of the struct itself like this:

typedef struct _struct_name {
    char array[5];
} struct_name;

Then you don't know what you want.

Jed Smith