// T4_Struct_115.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include "struct.h"
void initializeCoordinate(Coodinate *point);
int _tmain(int argc, _TCHAR* argv[])
{
/*
//1.typedef 在结构体创建时使用
typedef struct Coodinate
{
int x; //横坐标
int y; //纵坐标
}Coodinate1;
//2.typedef 在结构体定义外表声明
//3.struct Coodinate point;//原始状态
Coodinate1 point;
point.x = 5;
point.y = 6;
printf("x:%d;y:%d\n", point.x, point.y);
// 4.数组元素调用
Person user; // user是英语“用户”的意思
printf("您姓什么 ? ");
scanf_s("%s", &user.lastName,10);
printf("您名叫什么 ? ");
scanf_s("%s", &user.firstName,100);
printf("原来你的名字是 %s%s,失敬失敬\n", user.lastName, user.firstName);
// 5.定义结构体数组
ProgrammerLeague point1[10];
point1[1].x = 0;
point1[1].y = 0;
for (int i = 0; i < 10; i++)
{
point1[i].x = i;
point1[i].y = i;
printf("坐标是:(%d,%d)\n", point1[i].x, point1[i].y);
}
// 6.结构体变量初始化
Coodinate point = { 0, 0 };
Person player = { "", "", "", 0, 0 };
// 7.结构体指针
Coodinate *point2 = NULL;
*/
// 8.结构体作为函数参数
Coodinate point;
initializeCoordinate(&point);
printf("(%d,%d)", point.x, point.y);
return 0;
}
void initializeCoordinate(Coodinate *point)
{
point->x = 1;
point->y = 1;
}
C语言结构体
最新推荐文章于 2023-01-24 16:37:33 发布