C/Cpp指针

来源:互联网 发布:黑人和小女孩网络对唱 编辑:程序博客网 时间:2024/06/13 18:02

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