struct结构体基础知识

/*
 ============================================================================
 Name        : TestStruct.c
 Author      : lf
 Version     :
 Copyright   : Your copyright notice
 Description : struct结构体基础知识
 ============================================================================
 */

#include <stdio.h>
#include <stdlib.h>

//定义全局stundent结构体
struct stundent {
	char name;
	int age;
};

int main(void) {
	testStruct1();
	return EXIT_SUCCESS;
}

/**
 * 结构体的基本使用
 */
void testStruct1() {
	//使用全局结构体
	struct stundent s;
	s.name = 'A';
	s.age = 18;
	printStructInfo(s);
	printf("name=%c,age=%d\n", s.name, s.age);
	printf("=================\n");

	//定义局部teacher结构体
	struct teacher {
		char name;
		int age;
	};
	struct teacher t;
	t.name = 'B';
	t.age = 35;
	printf("name=%c,age=%d\n", t.name, t.age);
	printf("=================\n");

	//如下亦可初始化结构体,但是可读性不强
	struct teacher te={'C',55};
	printf("name=%c,age=%d\n", te.name, te.age);
}

void printStructInfo(struct stundent s){
	printf("name=%c,age=%d\n", s.name, s.age);
}

上一篇:JAVA学习(一):Java介绍及其平台、开发环境的配置与搭建


下一篇:PostgreSQL 函数式索引使用注意 - 暨非immutable函数不适合索引的原因