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

struct user{
    int age1;
    int *age2;
    int data1[10];
    int *data2;    
    char *name1;    // string literal
    char *name2;    // dynamicallay allocated string
    char name3[10]; // allocated when user is declared
};



void function(struct user user){
    user.age1 += 1;
    *user.age2 += 1;
    user.data1[0] = 5;
    user.data2[0] = 5;
}

int main(){
    struct user user;
    user.age1 = 10;
    user.age2 = malloc(sizeof(int));
    *user.age2 = 10;
    user.data2 = malloc(sizeof(int) * 10);
    for (int i = 1; i <= 10; i++){
        user.data1[i - 1] = i;
        user.data2[i - 1] = i;
    }
    user.name1 = "kai";
    user.name2 = malloc(sizeof(char) * 10);
    strncpy(user.name2, "kai", 10);
    user.name2[9] = '\0';
    strncpy(user.name3, "kai", sizeof(user.name3));
    user.name3[9] = '\0';

    function(user);
    
    printf("age1: %d *age2: %d\n", user.age1, *user.age2);
    printf("data1: ");
    for (int i = 0; i < 10; i++){
        printf("%d ", user.data1[i]);
    }

    printf("\n");
    printf("data2: ");
    for (int i = 0; i < 10; i++){
        printf("%d ", user.data2[i]);
    }

    printf("\n")
    printf("name1: %s name2: %s name3: %s", user.name1, user.name2, user.name3);

    return 0;
}