-->

program to understand struct pointer using typedef

//understanding struct pointer with typedef
#include <stdio.h>
#include <stdlib.h>
typedef struct reco
{
    int a;
    float b;
    char c;
    char city[100];
}record;
int main()
{
    typedef record *p;//pointer declaration of struct type record
    p pointer;//pointer declartion
    pointer=(p) malloc (sizeof(record));//memory allocation to variable pointer
    pointer->a=10;//value assignment
    pointer->b=3.14;//value assignment
    pointer->c='a';//value assignment
    strcpy(pointer->city,"Kathmandu");//value being copied
    printf("i=%d \nf=%f\nc= %c\n",(*pointer).a,(*pointer).b,(*pointer).c);//value printing
    printf("the city=%s\n",pointer->city);
    free(pointer);
    return 0;
}

No comments:

Post a Comment