zoukankan      html  css  js  c++  java
  • 【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)
    {
    }
    
  • 相关阅读:
    CircleImageView 圆形图片头像实现
    使用VisualStudio开发php的图文设置方法[xyytit]
    使用VisualSVN Server搭建SVN服务器[xyytit]
    比较全的JavaScript倒计时脚本[xyytit]
    jQuery对象转换为DOM对象(转)
    SQL Server多条件查询的实现
    GridView控件中的一些常见问题
    GridView中如何实现自定义时间货币等字符串格式?
    js关闭当前页面(窗口)的几种方式总结(转)
    Sql求和异常——对象不能从 DBNull 转换为其他类型
  • 原文地址:https://www.cnblogs.com/lwp-nicol/p/15067676.html
Copyright © 2011-2022 走看看