Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Leer Array Pointer Arithmetic Practice | Pointer Arithmetic
C++ Pointers and References

book
Array Pointer Arithmetic Practice

Access the row
Access the column
*arr
**arr
*(arr + row)
**(arr + column)
Taak

Swipe to start coding

  1. Access the last element of the second row of the array.
  2. Access the fourth element of the third row of the array.
  3. Output the sum of these elements.

Oplossing

cpp

solution

#include <iostream>

int main()
{
int row = 5, col = 5;
float arr[row][col] { {2.7, 5.1, 9.9, 5.5, 7.2 },
{4.4, 1.0, 2.5, 9.3, 1.1 },
{8.5, 5.1, 5.2, 9.6, 4.3 },
{0.5, 4.8, 0.9, 6.0, 3.7 },
{8.3, 3.0, 0.3, 7.4, 6.6 } };
std::cout << (*(*(arr + 1) + 4)) + (*(*(arr + 2) + 3));
}

Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 2. Hoofdstuk 4
#include <iostream>

int main()
{
int row = 5, col = 5;
float arr[row][col] { {2.7, 5.1, 9.9, 5.5, 7.2 },
{4.4, 1.0, 2.5, 9.3, 1.1 },
{8.5, 5.1, 5.2, 9.6, 4.3 },
{0.5, 4.8, 0.9, 6.0, 3.7 },
{8.3, 3.0, 0.3, 7.4, 6.6 } };
std::cout << (_(_(arr + _) + _)) + (*(*(arr + _) + _));
}
toggle bottom row
some-alt