第9章 指针

指针数组和数组指针

因为 [] 比 * 优先级 高

  • 指针数组 :一个数组里存放的是指针
    int * p[4];
  • 数组指针 :
    int (* p)[4];//指向一维数组的指针变量

指向指针的指针

int ** p;

以下代码p是存放 的是 str 的地址
str是指向字符串的字符指针。
*p 代表着 输出 str的值

#include<iostream>
using namespace std;
int main() {
	const char *str =  "HelloWorld" ;
	const char** p;
	p = &str;
	cout << "p =" << *p; //p = HelloWorld
	return 0;
}

指针数组作为main()函数的参数

#include <stdio.h>
int main(int argc,char * argv[]) {
	for (int i = 0; i < argc; i++) {
		printf("i= %d , argv[%d] = %s\n", i, i, argv[i]);
	}
	return 0;
}

image

posted @ 2021-05-13 00:13  appearAndLeave  阅读(64)  评论(0)    收藏  举报