Path: utzoo!utgpu!water!watmath!clyde!rutgers!sri-unix!quintus!ok From: ok@quintus.UUCP (Richard A. O'Keefe) Newsgroups: comp.lang.c Subject: Re: Arrays and structures Message-ID: <552@cresswell.quintus.UUCP> Date: 20 Jan 88 05:53:10 GMT References: <22151@linus.UUCP> Organization: Quintus Computer Systems, Mountain View, CA Lines: 43 In article <22151@linus.UUCP>, jfjr@mitre-bedford.ARPA (Jerome Freedman) writes: > Suppose I have the following > typedef struct > { > /* some irrelevant field declarations */ > char string[80]; > int vector [4]; > } structure_type; > > Now, tell me about the string and vector fields of second structure. > Since they are arrays then the fields are actually pointers. Wrong. Since they are arrays, the fields are actually ARRAYS. When you *MENTION* an array-valued field, as in structure_type Foobaz; .... Foobaz.string ... you get a pointer, just like if you mention ANY array you get a pointer. If you declare structure_type destination, source; ... destination = source; then the contents of the two fields (80*sizeof (char) bytes of string[] and 4*sizeof (int) bytes of vector[]) are moved. No pointers are moved, copied or changed, because there aren't any pointers. > Is the situation different if I change the type declaration to > ... > char *string; > int *vector; Yes. If you declare arrays, you get arrays. If you declare pointers you get pointers. The easiest way to answer questions like this is to type in a tiny example and ask your C compiler. cc -S foobaz.c -- UNIX /* look at foobaz.s */ cc foobaz/list/machine_code -- VMS /* look at foobaz.lst */ On other systems, you may have to ask a debugger.