C常用语法

& 取址 * 取值

#include “filename.h”是指编译器将从当前工作目录上开始查找此文件
#include<filename.h>  是指编译器将从标准库目录中开始查找此文件

#define PI 3.14159265 /*定义宏*/

#define S(a,b) a+b;/*定义宏*/

const int width = 100;定义类型常量

Char *func(void)

{

char str[]=”Hello Word”;

//这个是不能被返回的,因为str是个指定变量,不是一般的值,函数结束后会被注销掉

return str; #这里的str是内存地址

}

int a;

printf("%d",&a);

&a指的是内存地址

结构体:


 

代码
#方式一
struct stu / *定义学生结构体类型* /
{
char name[20]; / * 学生姓名* /
char sex; / * 性别* /
long num; / *学号* /
float score[3]; / * 三科考试成绩* /
};
struct stu student1,student2;/ * 定义结构体类型变量* /
struct stu student3,student4;
#方式二
struct data
{
int day;
int month;
int year;
} time1,time2;
方式三
struct
{
char name[20]; / *学生姓名* /
char sex; / *性别* /
long num; / *学号* /
float score[3]; / *三科考试成绩* /
} person1,person2; 
/ *定义该结构体类型变量* /
上述对结构体类型变量的三种定义形式均可在定义时初始化。结构体类型变量完成初始化后,即各成员的值分别为:student.name
="liping"、student.sex='f'、student.num=970541
student.score[
0]=98.5、student.score[1]=97.4、student.score[2]=95。其存储在内存的情况如图7-2所示。
int mouth;
int year;
} ;
struct stu
{
char name[20];
struct data birthday; 出/*生年月,嵌套的结构体类型*/
long num;
} person;
该结构体类型变量成员的引用形式: person.name 、person.birthday.day、person. birthday.month、person. birthday. y e a r、person.num 。

 extern a;将a变量扩展到当前文件

malloc(sizeof(person)) ;分配内存空间

calloc(3,sizeof(person));分配3个结构体需要的内存空间

struct stu *p;

p=(struct stu *)malloc(sizeof(person));/*通过强制转换得到分配内存的指针地址*/

链表生产图:

原文地址:https://www.cnblogs.com/liushannet/p/1867708.html