Need help understanding arrays.

Hello, I have this code here I need help understanding from homework assignment.

1
2
3
4
5
6
7
8
9
10
11
12
13
 #include <iostream>
using namespace std;
int main(void) {

	int pause;

	double matrix[][4] = { { 1, 2, 3, 4 },
	{ 2, 2, 3, 1},
	{ 3, 3, 3, 0 },
	{ 4, 1, 2, 4 } };

	int side = sizeof(matrix[0]) / sizeof(matrix[0][0]);
	bool issymmetric = true;


What I do not understand what "int side = sizeof(matrix[0]) / sizeof(matrix[0][0])" is doing. I was trying to check to see if this code will be symmetric or not.
closed account (9G3v5Di1)
I'm sorry for asking random q but it seems I couldn't post a new topic here in the Beginner section and it keeps giving errors after you click the 'submit' button.. how did you post yours?
@Lilil, it is working out how many columns there are in your matrix.

sizeof(matrix[0]) will tell you the total number of bytes to store row 0. (Probably 32).
sizeof(matrix[0][0]) will tell you the total number of bytes to store one element (probably 8).
Divide the two and you will get the number of elements in one row; here, it should give 4.

It's pretty redundant here, since you explicitly stated 4 earlier on.
you are basically dividing number of rows with number of rows and coloumns.
then checking the symmericity of the matrix defaultly declaring it as true(cause of some factor i dont know).

please dont take my word as final. ask your teacher and let me know if what i told was right for i am a noobie too
Sadly, that's not correct @srivats. You had better look up what sizeof() gives you in this context.

The present code doesn't check for symmetricity either: look at your maths notes to find out what a symmetric matrix is.
Last edited on
Topic archived. No new replies allowed.