Home > Back-end >  Problem: the array and pointer
Problem: the array and pointer

Time:11-14

I understand that is equal to the first element of an array name address, I will be the first reaction as such
 
Int odd []=,3,5,7,9 {1};
Int even []=,2,4,6,8 {0};
The decltype (odd) * arrPtr (int I) {
Return (I % 2)? Odd: even;
}



But the right is the fact that the front of the odd and even add the address-of symbol
 
Int odd []=,3,5,7,9 {1};
Int even []=,2,4,6,8 {0};
The decltype (odd) * arrPtr (int I) {
Return (I % 2)? & Odd: & amp; Even;
}


Why I write, where the knowledge is not enough, hope elder people glad, thank you very much

CodePudding user response:

Personally think that both are right, people generally in the form of written above; In addition, the Suggestions of the building Lord see arrPtr receiving data types, array name is address, odd can be directly assigned to int * pointer, such as:
Int * p=odd;
This assignment is no problem, if int * p=& amp; Odd; So, the compiler will have a warning: type does not match; Int (* p) [5]=& amp; Odd; That is no problem,

CodePudding user response:

The decltype (odd) is itself a pointer type, if you write like this is no problem,
 
Int * arrPtr (int I) {
Return (I % 2)? Odd: even;
}

CodePudding user response:

Return value has an array name, returns the address of the entire array, add the address after symbol is an element of address ~ such as print sizof (add) result is 20, but the sizeof (& amp; Add) is 4, isn't it...

CodePudding user response:

https://blog.csdn.net/yaoyuantk/article/details/2031635? Utm_medium=distribute. Pc_relevant_bbs_down. None - task - blog - baidujs - 1. Nonecase& Depth_1 - utm_source=distribute. Pc_relevant_bbs_down. None - task - blog - baidujs - 1. Nonecase
We can see this blog post,
  • Related