Displaying struct members used together with typedef, redefine the 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 struct members program example used with typedef, redefining the new name

To show: The typedef specifier and struct data type usage in C programming

 

// typedef specifier

#include <stdio.h>

 

// typedef <oldname> <newname>

typedef struct mystructtag

{

int x;

double y;

char* z;

} mystruct;

 

int main(void)

{

mystruct Test1, *Test2;

 

Test1.x = 111;

Test1.y = 1.111;

 

printf("Test1.x = %d\nTest1.y = %f\n", Test1.x, Test1.y);

printf("Let check the size of the mystruct: %d\n", sizeof(mystruct));

 

Test1.z = "This is a string";

Test2 = &Test1;

 

printf("Test1->z = %s\n",Test2->z);

return 0;

}

 

Output example:

 

Test1.x = 111

Test1.y = 1.111000

Let check the size of the mystruct: 24

Test1->z = This is a string

Press any key to continue . . .

 

 

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