Arrays

Need to answer the ffg questions but battling to find the answers:

1. Given the following array declaration, what is the value stored in the scores[1][1] element?
int scores[3][3] = { {1, 2, 3}, {4, 5, 6}, {7, 8, 9} };

2. Given the following array declaration, what is the value stored in the scores[2][2] element?
int scores[3][3] = { {1, 2, 3} };

3.
Wouldn't it just be easier to test it yourself rather than scouring the interwebs? Show some effort.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// Example program
#include <iostream>

int main()
{
    {
        // 1. Given the following array declaration, what is the value stored in the scores[1][1] element?
        int scores[3][3] = { {1, 2, 3}, {4, 5, 6}, {7, 8, 9} };
        
        std::cout << scores[1][1] << std::endl;
    }

    {
        // 2. Given the following array declaration, what is the value stored in the scores[2][2] element?
        int scores[3][3] = { {1, 2, 3} };
        
        std::cout << scores[2][2] << std::endl;
    }
}


But anyway, here's the basic rules of initializing arrays:
int arr[5][3]; Allocates a 5x3 array on the stack, but leaves its values undefined.
int arr[5][3] = {}; Initializes all elements to zero.

Doing anything else will initialize everything to zero except what you explicitly assign:
int arr[5][3] = { {42, 43} }; will make [0][0] be 42, [0][1] be 43, but everything else will be 0.
thanks for being so frank and helpful at the same time
Topic archived. No new replies allowed.