Check the offset of a structure field - C Structure

C examples for Structure:Structure Value

Description

Check the offset of a structure field

Demo Code

#include <stdio.h>
#include <stddef.h>

struct car/* ww  w .j  a  va2  s.  c o m*/
{
    char brand[30];
    char model[30];
    double hp;
    double price;
};
int main(void)
{
    size_t into = offsetof(struct car, hp);  /* offset of hp member */
    printf("%zd\n", into);
    return 0;
}

Result


Related Tutorials