Pointers and arrays in C++
Level 3110 keystrokes
An array name converts to a pointer to its first element. p + i points i elements further on, so *(p + i) is the same as arr[i]. Prints 10 20 30.
C++ code
1int arr[] = {10, 20, 30};// arr converts to a pointer to arr[0]; no & is needed2int* p = arr;3for (int i = 0; i < 3; i++) { // p + i moves by i elements (not bytes); * reads the value there4 cout << *(p + i) << " ";5}// Ends the line after 10 20 306cout << endl;Output
10 20 30
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this C++ code and how often they appear.
<× 7;× 6+× 3=× 3,× 2"× 2(× 2)× 2{× 2}× 2