#include <iostream>#include <windows.h>using namespace std;void firstBegin(int*& p, int value) { while(*p <= value) { p++; }}void main() { int vec[] = {1,12,32,44,33,6,85,4,100}; cout<<vec<<endl; cout<<&vec<<endl; cout<<&vec[0]<<endl; //int* result = vec; //succeed [color=#FF0000]int* result = &vec;//error ? why?[/color] //int* result = &vec[0]; //succeed firstBegin(result,60); cout<<"Begin at "<<*result<<endl; system("pause");}
[解决办法] If the type of an expression or subexpression is ``array of T,'' for some type T, then the value of the expression is a pointer to the first object in the array, and the type of the expression is altered to ``pointer to T.'' This conversion does not take place if the expression is in the operand of the unary & operator, or of ++, --, sizeof, or as the left operand of an assignment operator or the . operator. Similarly, an expression of type ``function returning T,'' except when used as the operand of the & operator, is converted to ``pointer to function returning T.'' [解决办法] 数组名在3种情况下不会转换为指针:其中一种就是 &array [解决办法]