"dj" <> wrote in message news

ine.LNX.4.44.0405181555510.15999-...
> I've read section 6 of the FAQ, but still am a bit confused...
> Please refer to the comments in the following
> code for my questions:
> -----------------------------------------------------------
> #include <stdlib.h>
> #include <stdio.h>
> #include <memory.h>
>
>
> #define L_DATE 8
>
> typedef struct
> {
> char date1[L_DATE];
> char date2[L_DATE];
> } my_record_t;
>
> my_record_t my_rec;
>
> void my_func(void);
>
> int main(void)
> {
> char my_char[L_DATE];
> memcpy(my_rec.date1, "20040101", L_DATE);
> memcpy(my_rec.date2, "20040202", L_DATE);
>
> /*
> ** I understand that "my_char" is the same as
> ** "&my_char[0]", but what about "&my_char"?
> ** I was surprised to find out that
> ** "my_char" == "&my_char"! (that is an exclamation,
> ** not a "not").
> */
A simple example should be helpful for you to understand the difference between
`my_char' and `&my_char'. Their values, thought numerically, are same but their
semantic meanings are not.
The address-of operator when applied to an object yields a pointer to (the
location of) that object. For example,
int a, *p;
p = &a;
&a yields the address of the integer object a. An address can be represented by
a pointer. In other words, a pointer is an object which can store the lvalue of
a compatible object. So the declaration,
int *p;
says that p is pointer to an int, and can store the lvalue of a (&a).
Similarly the declaration,
char my_char[L_DATE];
says my_char is an array of char. And, the address-of operator would yield the
address of the array object as it did for the integer object above. Now, what
should be the pointer type to store the address of the array? Let us build the
declaration of pointer to an array of char:
The basic type of pointer is `char', and the pointer declaration is
char *ptr;
but, this not a pointer to an array; it is, but, pointer to a char. So, a
pointer to the array is:
char (*ptr)[L_DATE];
Now, the address can be taken.
ptr = &my_char;
Save my English, I think the above points are OK. Another point, I think,
is using identifiers beginning with "L_" is reserved (but, I'm not sure).
What Mr. Arthur was saying about "The Rule" is here:
http://web.torek.net/torek/c/expr.html#therule
[..]
> any help or comments are appreciated.
>
> thanks,
>
> -dj
>
--
"Thinking should become your capital asset, no matter whatever
ups and downs you come across in your life."
- Dr. APJ Abdul Kalam, The President of India