【c学习-4】

//递归函数,调用自身
#include<stdio.h>
int fibFunc(int n)
{
    if(n==1 || n==2){
        return 1;
    }else{
        return fibFunc(n-1)+fibFunc(n-2);
    }
}

int main(){
    int n=fibFunc(3);
    printf("n=%d
",n);
}

#include<stdio.h>
void Function(){
    printf("%s",__func__);
}
int main(){
    Function();
}




#include<stdio.h>
void Function(){
    static int i=18;//静态局部变量定义
    printf("i=%d
",i++);
}
int main(){
    int j=0;
    for (j=0;j<10;j++){
        Function();
    }
}



int main(){
    const int x=1;//使变量只读
//    x=2;
    printf("%d
",x);

}

#include<stdio.h>
int main(){
    int *p;
    int a=1;
    p=&a;
    *p=NULL;
    printf("p=%p
",p);
    printf("*p=%d
",*p);
    printf("&a=%p
",&a);    
    printf("a=%d
",a);
    void *p1=&a;
    * int(*)p1=18;
    
}

  



i nt c=19;
    //int const *p4;
    //const int *p4;     //const在指针的左边,可以改变指针的指向,不可以改变指针的值; 
    //int *const p4;    //const在指针的右边,不可以改变指针的指向,可以改变指针的值;    
    //const int *const p4;//特殊具有两个const,使指向和值都为只读;             
    p4=&c;
    //*p4=20;

    int arry[10]={0,1,2,3,4,5,6,7,8,9};
    int *p1=&arry[1];
    int *p2=&arry[8]  ;
    long number=p2-p1;
    printf("number=%d
",number);
    int x=10;
    int *p=&x;
    printf("*p=%p
",*p);
    printf("*p+1=%p
",*p+1);    //指针运算 

}



#include<stdio.h>
int main(){
/*
struct People liupeng ;
liupeng.age=18;
//printf("%d
",Pepole.numer);
strcpy(liupeng.name,"liupeng");
printf("%s
",liupeng.name);
//printf("%d
",liupeng.age);
*/                    //结构体
/*
    struct Pepole{
    int id;
    char name;
    char sex;
    double age;    
};
struct Pepole x;
x.id=18;
x.name='lp';
printf("x.id=%d
",x.id);
*/                  //使用结构体变量访问结构体元素 
struct Pepole{
    int age;
    char name;    
};
struct Pepole* p;
struct Pepole x={19"lp"}; 
p=&x;
printf("p->name=%s
",p->name);
//p->id
}




#include<stdio.h>
    struct People {
        int age;
        char* name;
    };
    union libray{
        char name;
        int id;    
    };
enum ABCColor {
    Red,
    Blue,
    White
};
int main(){
    enum ABCColor myColor;   //枚举型 
    myColor=Red;
    myColor=Blue;
    myColor=White;
    printf("myColor=%d
",myColor);
    struct People* p;
    struct People x={19,"lp"};
     p=&x;
    printf("p->name=%s
",p->name);  //使用结构体指针访问成员 
    printf("p->age=%d
",p->age);
    printf("x.name=%s
",x.name);    //使用结构体变量访问成员 
    union libray y;       //联合体 
    y.name="poem";
    printf("y.name=%s
",y.name);    
    
} 

#ifndef SeqList_h  //用户自定义库文件 
#define SeqList_h

#include<stdio.h>

struct SeqList{
    int dataArray[100];
    int nLength;
};
typedef int dataType;

#endif


#include<stdio.h>
#include "SeqList.h"
int main(){
dataType myAge=18;
printf("myAge=%d ",myAge);
return 0;
}
















要保持着对知识的渴求,给自己充电,不要这荒废了短暂的时光;
原文地址:https://www.cnblogs.com/activecode/p/9482927.html