P207. WAP to understand typedef.

 

/* (A - Typedefing a integer)

#include<stdio.h>

typedef int INTEGER;

void main()

{

        int i;

        INTEGER j;

        printf("%ld %ld\n",sizeof(i),sizeof(j));

}

*/

 

/* (B - Typedefing a unsigned char)

#include<stdio.h>

typedef unsigned char UCHAR;

void main()

{

        UCHAR c;

        printf("%ld\n",sizeof(c));

 

}

*/

 

/* (C - Typedefing an array)

#include<stdio.h>

typedef int ARR[5];

void main()

{

        ARR a1;

        printf("Size of a1 : %ld\n",sizeof(a1));

 

        int i;

        for(i=0;i<5;i++)

                scanf("%d",&a1[i]);

 

 

        for(i=0;i<5;i++)

                printf("%d ",a1[i]);

}

*/

 

/* (D - Typedefing a pointer)

#include<stdio.h>

typedef int *IPTR;

void main()

{

        int i = 10;

        IPTR p;

        p=&i;

        printf("%d\n",*p);

}

*/

 

 

 

/* (E - Typedefing a structure)

#include<stdio.h>

 

//Syntax 1

struct one

{

char ch;

int i;

float f;

};

typedef struct one O;

 

 

//Syntax 2

typedef struct one

{

char ch;

int i;

float f;

}O;

 

void main()

{

        O o1;

        o1.ch = 'a';

        o1.i = 10;

        o1.f = 23.5;

        printf("%c %d %f\n",o1.ch,o1.i,o1.f);

 

}

Comments