[ create a new paste ] login | about

Link: http://codepad.org/Cmtc8Teq    [ raw code | output | fork ]

mohit_at_codepad - C, pasted on Feb 19:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
struct abc {
  char ch[15];
  short int si[12];
  int def;
  long int li[10];
};

void *getAddr(void *def)
{
  const unsigned int ui = &((struct abc *)0)->def;
  return def - ui;
}

int main()
{
  struct abc sa;
  printf("Address of sa = %p\n", &sa);
  printf("Address of sa = %p\n", getAddr(&sa.def));
  return 0;
}


Output:
1
2
Address of sa = 0xbf8a85fc
Address of sa = 0xbf8a85fc


Create a new paste based on this one


Comments: