3のC言語のポインタの基礎

ユニバーサルヌルポインタのポインタのポインタフィールド

int *p = NULL;

int a =1000;
p = &a;
void* xx = p;
*(int*)p = 1000000;
printf("%d \n",*p);

constポインタの変更

const int a = 10;
int b = 100;

//第一种
int *p = &a;
p = &b;    (V)
*p = 1000; (V)
//第二种
const int *p = &a;
 p = &b;  (V)
*p = 1000; (X)

//第三种 
int * const p = &a;
p = &b;  (X)
*p = 1000; (V)

//第四种 
const int * const p = &a;
p = &b;  (X)
*p = 1000; (X)

ポインタ配列

char* arr[] = {"aaaa","bbbb","cccc"};
arr[0]表示"aaaa"的地址值
*(arr[0]+1) 表示“aaaa”中第二个元素的值

[]的优先级高 ,是的char* arr[]的本质是 一个数组,数组的元素为指针类型

配列ポインタ

char hello[] = {"hello world"};
char (*pHello)[] = &hello;
pHello是一个指针类型,指向的元素为char[]

ポインタのパラメータと戻り値

当指针或者数据做为实参时,都被按照指针进行处理。
如果是非字符指针或者所有的数组,一定要传递其长度进入;如果是字符串指针,可以通过strlen判断或者‘\0’的标志判断。
返却値
char* test(){
    //Address of stack memory associated with local variable 'hello' returned
    // 字符数组,创建在栈区
    char hello[] = "hello world";
    // 字符串常量 常量区
//     char *hello = "hello world";
    return hello;
}

int main(int argc, const char * argv[]) {
    char * p = test();
    printf("%p \n",p);
    printf("%s \n",p);
    return 0;
}
公開された98元の記事 ウォンの賞賛6 ビュー20000 +

おすすめ

転載: blog.csdn.net/dirksmaller/article/details/103788850