Whilst performing a 'typedef int triple', I get results that are confusing to me. The type of the stack variable is indeed an int *. However, 's' is not an int, but an int * also. Furthermore, when dereferencing stack, the resulting lvalue is an int, as I would expect, but when assigning this to 's', I get the pointer to this triple, presumably because s is defined as an int *, not an int.
My questions are: why is 's' defined as an int *, instead of an int and why does assigning an int to 's' result in the assignment of the address of this particular int?
The code has been compiled with gcc-4.1.2.
typedef int triple;
int i, j;
printf("sizeof(stack): %i\n", sizeof(stack));
stack = (triple *) malloc(10*sizeof(stack));
if(stack == NULL)
printf("sizeof(stack) after malloc: %i\n", sizeof(stack));
for(i = 0; i < 10; i++)
for(j = 0; j < 3; j++)
stack[i][j] = i*3 + j;
s = stack;
printf("s, s, s: %i, %i, %i\n", s, s, s);