【C语言】C语言基础知识回顾

C语言基础知识回顾

一、结构体类型

定义:用系统已有的不同基本数据类型或者用户自定义的结构型组合成的用户需要的复杂数据类型。

struct Student
{ 
    int num;
    char name[20];
    int age;
    float score;
}
struct Student s1,s2;
s1.num = 101;
s2.num = 102;

使用typedef改进结构体

typedef int ElemType;          
Integer i,j; //以后可以直接用Integer代替int,等价于 int i,j; 
/*———————————————————————————————*/
	
typedef  char  ElemType;
typedef struct LNode
{   
    ElemType  data;
	struct LNode *next;
}LNode;

/*———————————————————————————————*/
typedef struct Student
{ 
    int num;
    char name[20];
    int age;
    float score;
}Student;

Student s1,s2;
s1.num = 101;
s2.num = 102;

二、指针类型和引用

详解: https://blog.csdn.net/qq_35038153/article/details/77968036

指针:一个变量的地址称为该变量的“指针”,专门存放变量地址的一类变量成为“指针变量”。

引用:顾名思义是某一个变量或对象的别名,对引用的操作与对其所绑定的变量或对象的操作完全等价。

/*———————————————————————————————*/ 
int  *b;   //这里的*是定义指针的意思
int  a = 10;
b = &a;    //这里的&是取地址的意思
*b = 1;    //这里的*是取元素值的意思
printf(“%d”,a); a=1;

/*———————————————————————————————*/
int a = 10;
int b = a; //这里的&是定义一个引用变量的意思
printf(“%d”,b);b=10
a = 11
printf(“%d”,b);b=10

三、函数

/*———————————case1————————————————————*/
void fun1(int num)
{
    num++;
}

int a = 1;
fun(a);
//
num = a;

printf(“%d”,a);
a = 1
    
    
int fun1(int num)
{
    num++;
    return num;
}

int a = 1;
a = fun(a);
printf(“%d”,a);
a = 2;
/*———————————case2————————————————————*/
void fun2(int *num,int *b)
{
    num++;
    b++;
}
int a = 1;
int b = 1;
fun(&a,&b); //形参是指针的时候,传入变量的地址
// *num = &a;
printf(“%d”,a);
a = 2
 b = 2
/*———————————case3————————————————————*/

void fun3(int &num)
{
    num++;
}
int a = 1;
fun(a); //形参是引用的时候,直接传入变量
// int &num = a;
printf(“%d”,a);
a = 2
/*———————————case4————————————————————*/
void fun4(int a[])
{
    a[1]++;
}
int a[10];
a[0] = 1;
fun(a); //一个数组的字母就是一个指针
		// a 就是一个指针 
printf(“%d”,a[0]);
a[0]= 1;
a[1]= 1;
/*———————————————————————————————*/

四、代码中的C语言

/*———————————case1————————————————————*/ 
void insertElem(Sqlist &L,int x)
{
    
}

/*
   形参需要传入L的引用,L会随着调用函数后改变而改变,x不变
*/

/*———————————case2————————————————————*/ 
int insertElem(Sqlist &L,int x)
{
    return x;
}

void insertElem(Sqlist &L,int &x)
{
    
}
/*———————————case3————————————————————*/ 
void insertElem(Sqlist L,int &x)
{
}

/*———————————case4————————————————————*/ 
int findMin(int A[],int n)
{
}
posted @ 2021-07-27 20:04  梁君牧  阅读(221)  评论(0编辑  收藏  举报