为您找到"
int a[]={1,2,3,4,5};int *p;p=&a,这样的操作不行?
"相关结果约100,000,000个
C Programming questions and answers section on "Pointers Find Output of Program" for placement interviews and competitive exams: Fully solved C Programming problems with detailed answer descriptions and explanations are given for the "Pointers Find Output of Program" section - Page 3.
Remember how pointer arithmetic in C++ works: adding an integer to a pointer operates in units of the type pointed to. a has type int [5], so &a is a pointer to an array of 5 ints. Thus &a+1 points to the next array of 5 ints. This would make sense if it were part of a 2-dimensional array, but it is not, so it's pointing to garbage. Casting to another type just makes things worse. - Nate ...
EXPLANATION: int a [] = {1,2,3,4,5}; this statement creates a array with name "a" and contains 1,2,3,4,5. the index is a integer used to denote positions of the elements in a array.
Describe how the two arrays index and data are related to one another after the code snippet below executes: int* index [5]; int data [10] = {4, 8, 1, 3, 5, 9, 3, 2, 6, 0}; int i = 0; int* p = &data [9]; for (int i = 0; i < 5; i++) { index [i] = p; p--; } Select one: a. The elements of index point to the elements of data as follows:index [0] points to data [9]index [1] points to data [8]etc ...
Here, p is pointer to 0th element of the array arr, while ptr is a pointer that points to the whole array arr. The base type of p is int while base type of ptr is 'an array of 5 integers'.
The difference between int* p=new int [N] and int* p=new int (N) This statement allocates a piece of memory, initializes an object of type int by value, and returns its pointer to the defined p. The initial value of int pointed to by p is 0. The meaning of this sta...
If p points to a [0] then: p + 1 = &a [0] + 4 = the address of the array element a [1] !! p + 2 = &a [0] + 8 = the address of the array element a [2] !!
int a []= {1,2,3,4,5}实际上是用 {1,2,3,4,5}初始化空间后,分配给a ;int*p这个定义根据ANSI C++的规定p为指针,必须显式为其分配空间,否则p指向的未知不定。 二者的差异是Ansi/ISO C++规范决定的。
int **p=q意思是:p本身是一个指针,p指向一个指针。 q=&p , q存的是p的地址。 发表于 2016-04-16 14:48:57 回复 (0) 0 陈木木 要是能在这里留下这道题的解题思路,就再好不过啦 发表于 2015-04-24 15:28:50 回复 (0)
这个问题的关键是理解 &a a是一个数组名,也就是数组的首地址。对a进行取地址运算符,得到的是一个指向数组的指针!!!!这句话尤为重要!也就相当于int (*p) [5] = &a;p是一个指针,它指向的是一个包含5个int元素的数组!!那么执行p+1后,p的偏移量相当于 p + s