Arrays in C: Pointers vs Structures

  • Thread starter Thread starter transgalactic
  • Start date Start date
  • Tags Tags
    Array
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
5 replies · 2K views
transgalactic
Messages
1,386
Reaction score
0
Code:
printf("%p\n", array);

i know that unlike other variables
when we want to do some operation on an array
it uses the physical address of the array

but there are many cells in the array
does it prints every one of them??

does the array always defined as pointer ??
even if we make every cell as int

printf("%d\n", array);

will it make any difference?
 
Physics news on Phys.org
printf("...", array) is actually read as:
printf("...", &array[0]);

So that prints out the memory address of the first array index.
 
&integer =the address of the variable ?
 
Note that structures work differently.

Code:
typedef struct {arrayofints[5];}SAI;

static SAI sai0 = {1,2,3,4,5};
static SAI sai1;

int main()
{
    sai1 = sai0;    // copies entire structure
    return(0);
}

I do recall that some older C compilers treated arrays the same as structures are handled now, but it's not part of the C language now (I don't know what if anything changed between the orignal C language and what exists today).