The typedef and struct - simplifying the struct definition into new name



Compiler: Visual C++ Express Edition 2005

Compiled on Platform: Windows 2003 Server Standard Edition

Header file: Standard

Additional library: none/default

Additional project setting: Set project to be compiled as C

Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C Code (/TC)

Other info:

To do: Displaying some data of the struct type and simplifying the enum definition using typedef

To show: The typedef and struct C program example demonstrating the simplified enum definition




// typedef and struct program example

#include <stdio.h>


// typedef and struct definition

typedef struct TestStruct


int p;

char q;

double r;

} mine;


void main(void)


mine testvar; // the declaration becomes simpler


testvar.p = 200;

testvar.q = 'T';

testvar.r = 1.234;


printf("testvar.p = %d\ntestvar.q = %c\ntestvar.r = %.4f\n", testvar.p, testvar.q,testvar.r);



Output example:


testvar.p = 200

testvar.q = T

testvar.r = 1.2340

Press any key to continue . . .



C and C++ Programming Resources | C & C++ Code Example Index