Int a [5] = {1, 2, 3, 4, 5}; printf ("% d \ n", * (int *) (& a + 1)-2 );, printf % d
What is the result of a certain convincing pen question in a certain year? The answer is 4. Why?
My understanding (do not know if it is correct ):
& A is an array pointer of the int type [5], so & a plus 1 is actually a + sizeof (int) * 5, that is, a [5], forced conversion to int type is a + 5, and the result is a [3] = 4.
# Include <stdioh> void main () {int a [5] = {1, 2, 4, 5}; int * ptr = (int *)(&
The key to this question is int * ptr = (int *) (& a + 1); In this sentence, & a indicates obtaining the first address of the storage area of array, add 1 to indicate the address of the storage area of array a, which causes the ptr pointer to point to the address of the storage unit behind the last element of the array. After ptr minus 1, for data access, the value of the previous storage unit of the ptr pointer is accessed. All the final answers are 2, 5.
Int a [] = {1, 2, 4, 5}; int * p = a; printf ("% d \ n", * p); why is the result 1?
The output sequence is run from right to left, and the last is * P. Because * p = a, * P outputs the first element of the array.
* P = 1;
-- (* P) First Auto minus = 0, * p = 0;
* P -- first copy = 0;
* P = 0;
(* P) ++ first copy = 0;
* In (++ p), ++ p automatically adds 1 to the element whose coordinates are 1. a [1] = * (++ p) = 2;
* P also points to a [1], * p = 2;