Using Pointer to structure

 #include<stdio.h>

#include<string.h>


struct employee{

    int code;

    float salary;

    char name[20];

};


int main(){

    struct employee e1;

    struct employee *ptr;


    ptr = &e1;

    //(*ptr).code = 101; //or you can also write: ptr->code = 101;

    ptr->code = 101;

    printf("%d", e1.code); 


    return 0;

}

Comments

Popular posts from this blog

Snake game.c

Type declaration

Array with function