Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

offsetof - Offset of a structure component from the start of the structure

&pagelevel(4)&pagelevel

Definition  

#include <stddef.h>

size_t offsetof(type,component);

offsetof returns the offset in bytes between the structure component component and the start of the structure (label) of type type.
offsetof is a macro.

Return val.

Offset of the structure component from the start of the structure in bytes.

Note

If the specified structure component is a bit field, the behavior is undefined.

Example

#include <stdio.h>
#include <stddef.h>
struct S1 {
   char c;
   int  i;
   double d;
};
int main(void)
{
  typedef struct S1 t_s1;
  printf("offsetof(struct S1, c) = %d\n", offsetof(struct S1, c) );
  printf("offsetof(struct S1, i) = %d\n", offsetof(struct S1, i) );
  printf("offsetof(struct S1, d) = %d\n", offsetof(struct S1, d) );
  printf("\n");
  printf("offsetof(t_s1, c) = %d\n", offsetof(t_s1, c) );
  printf("offsetof(t_s1, i) = %d\n", offsetof(t_s1, i) );
  printf("offsetof(t_s1, d) = %d\n", offsetof(t_s1, d) );
  printf("\n");
  return 0;
}