Hi
Revisiting c programming after oh ages (15 years :-() and writing a pointer to a struct.
The program at the bottom gives me
Struct Alpha using values is 9, 7, 2.434000:
Address of pointer ptr1 is 134510852
Size of struct is 12
Values are 9 , 7 and 0.000000
Using -> notation x is 9
Using -> notation y is 7
Using -> notation depth is 2.434000
However I cannot see for the life of me why
printf("Values are %d , %d and %f\n",*ptr1, *ptr1, *ptr1);
gives
Values are 9 , 7 and 0.000000
Why does the same reference (right term?) give different results and more specifically the first two values in the instance of my struct ?
TIA Paul
Code:
/*
* File: newmain.c
* Author: paulj
*
* Created on 10 June 2009, 20:11
*/
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char** argv) {
struct Position {
int x;
int y;
float depth;
};
struct Position Alpha;
Alpha.x = 9;
Alpha.y = 7;
Alpha.depth = 2.434;
;
struct Position * ptr1;
ptr1 = Α
printf("Struct Alpha using values is %d, %d, %f:\n", Alpha.x, Alpha.y, Alpha.depth);
printf("Address of pointer ptr1 is %d\n",ptr1);
printf("Size of struct is %d\n",sizeof(Alpha));
printf("Values are %d , %d and %f\n",*ptr1, *ptr1, *ptr1);
printf("Using -> notation x is %d\n",ptr1->x);
printf("Using -> notation y is %d\n",ptr1->y);
printf("Using -> notation depth is %f\n",ptr1->depth);
return (EXIT_SUCCESS);
}