C提高_day03_const小专题

const int a;     //代表整型变量a不能被修改

int const b;

const char *c;  //看const 是放在*的左边还是右边 看const是修饰指针变量,还是修饰所指向的内存空变量

char * const d; char buf[100]

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

void main()
{
    const int a=10;
    //a=11;
    int *p;
    {
        p=&a;
        *p=100;        //通过指针可以修改a的值
        printf("a:%d 
",a);
    }

        system("pause");
        return;
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void getmem1(char *p)
{
    //p=1;
    //p=3;
    //
    p[1]='a';
    
    return;
}

void getmem2(char * const p)
{
    p=1;
    p=3;
    //
    p[1]='a';
    
    return;
}

void main()
{
    char *p1= NULL;
    const char *p2= NULL;
    p2=1;
    printf("helllo...
");
    system("pause");
    return;
}
Stay hungry,Stay foolish
原文地址:https://www.cnblogs.com/zhesun/p/4959860.html