C/Cpp指针

C/Cpp指针

参考:

http://en.cppreference.com/w/c/language/pointer
动画演示 http://cslibrary.stanford.edu/
https://en.wikibooks.org/wiki/C_Programming/Pointers_and_arrays
http://publications.gbdirect.co.uk/c_book/chapter5/pointers.html
http://publications.gbdirect.co.uk/c_book/chapter5/function_pointers.html

四种“普通”变量

  • int i; // integer variable ‘i’ 变量i里面放int型值,用int规则来访问
  • int *p; // pointer ‘p’ to an integer 变量p里面只能放地址(即指针),用pointer规则来访问
  • int a[]; // array ‘a’ of integers 数组,连续存储着的同型变量
  • int f(); // function ‘f’ with return value of type integer 函数,把f用function规则来访问

其中:
int arr[10]; // arr is an array of 10 const ints

int arr[5];
printf("length is: %ld and %ld", sizeof(arr[0]), sizeof(arr));

//运行结果:
length is: 4 and 20
  • int **pp; // pointer ‘pp’ to a pointer to an integer
  • int (*pa)[]; // pointer ‘pa’ to an array of integer
  • int (*pf)(); // pointer ‘pf’ to a function with return value integer
  • int *ap[]; // array ‘ap’ of pointers to an integer
  • int *fp(); // function ‘fp’ which returns a pointer to an integer

  • int ***ppp; // pointer ‘ppp’ to a pointer to a pointer to an integer

  • int (**ppa)[]; // pointer ‘ppa’ to a pointer to an array of integers
  • int (**ppf)(); // pointer ‘ppf’ to a pointer to a function with return value of type integer
  • int *(*pap)[]; // pointer ‘pap’ to an array of pointers to an integer
  • int *(*pfp)(); // pointer ‘pfp’ to function with return value of type pointer to an integer
  • int **app[]; // array of pointers ‘app’ that point to pointers to integer values
  • int (*apa[])[]; // array of pointers ‘apa’ to arrays of integers
  • int (*apf[])(); // array of pointers ‘apf’ to functions with return values of type integer
  • int ***fpp(); // function ‘fpp’ which returns a pointer to a pointer to a pointer to an int
  • int (*fpa())[]; // function ‘fpa’ with return value of a pointer to array of integers
  • int (*fpf())(); // function ‘fpf’ with return value of a pointer to function which returns an integer

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值