0

I am have one question. Lets say we have a struct which is defined as follows:

 typedef struct test { 
   int x;
   int y;
 };

Now if I create a instance of this struct as follows;

  test object;

So will the " &object == &object.x "??

Vicky
  • 41
  • 1
  • 4
    http://stackoverflow.com/questions/7312555/in-c-does-a-pointer-to-a-structure-always-point-to-its-first-member – nnn Nov 21 '15 at 22:06
  • You probably meant `typedef struct { ... } test;`. This is not related to the question you asked (which has been answered since), but it's generally a good idea to post actual code. – dxiv Nov 21 '15 at 22:29

1 Answers1

0

Yes the address of the first data member of the structure will be equal to the address of the object of the structure itself.

From the C Standard (6.7.2.1 Structure and union specifiers)

15 Within a structure object, the non-bit-field members and the units in which bit-fields reside have addresses that increase in the order in which they are declared. A pointer to a structure object, suitably converted, points to its initial member (or if that member is a bit-field, then to the unit in which it resides), and vice versa. There may be unnamed padding within a structure object, but not at its beginning.

Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335