writing binary/struct data to file

I am trying to write binary data to a file. My program below:

#include <stdlib.h>
#include <stdio.h>

struct tinner {
  int j;
  int k[3];
};

struct touter {
  int i;
  struct tinner *inner;
};

int main() {
        struct touter data;
        data.i = 10;

        struct tinner in;
        in.j = 5;
        in.k[0] = 1, in.k[1] = 2, in.k[2] = 3;
        data.inner = &in;

        printf("sizeof(data)=%d, sizeof(in)=%d\n", sizeof(data), sizeof(in));

        FILE *fp = fopen("test.dat", "w+b");
        fwrite((const void *) &data, sizeof(data), 1, fp);
        fflush(fp);
        fclose(fp);
}

The output that I get is:
sizeof(data)=8, sizeof(in)=16

Why is it so ? Why is the full structure that is hold by the variable 'data' not written to the file ? What can I do so that full data is written that is when I write instances of touter, touter.tinner is also written ?

-Satish

You are not writing tinner to the file - just a pointer which means nothing when you try to read the file try:

#include <stdlib.h>
#include <stdio.h>

struct tinner {
  int j;
  int k[3];
};

struct touter {
  int i;
  struct tinner inner;
};

int main() {
        struct touter data;
        data.i = 10;

       
        data.inner.j = 5;
        data.inner.k[0] = 1, data.inner.k[1] = 2, data.inner.k[2] = 3;
        

        printf("sizeof(data)=%d\n", sizeof(data) );

        FILE *fp = fopen("test.dat", "w+b");
        fwrite((const void *) &data, sizeof(data), 1, fp);
        fflush(fp);
        fclose(fp);
        return 0;
}
The output that I get is:
sizeof(data)=8, sizeof(in)=16
Why is it so ?

int i;:::: 4 bytes for integer
struct tinner *inner;::::::: 4 bytes for pointer.

How can I write the full structure (obviously I am not interested in writing the pointer but the actual record) ?

(obviously I am not interested in writing the pointer but the actual record)

Copy the actual record into some buffer using sprintf, then write it to the file.