Skip to content

Instantly share code, notes, and snippets.

@AaronGoldsmith
Last active November 21, 2016 00:57
Show Gist options
  • Save AaronGoldsmith/484c18cfb0637a18d1ec344090514fb7 to your computer and use it in GitHub Desktop.
Save AaronGoldsmith/484c18cfb0637a18d1ec344090514fb7 to your computer and use it in GitHub Desktop.
matrix structure in c++
struct Matrix{
// you cannot initialize a variable ....
// ... (assign it values) inside the structure
int matrix[3][3];
};
void printMatrix(struct Matrix *m){
for (int i = 0;i<3;i++){
for(int j = 0; j<3; j++){
// you have to print out from m[][]
// m is of type Matrix
cout << m[i][j] << " ";
}
cout<<endl;
}
}
void main(String args[]){
// initialize the matrix in main()
struct Matrix X = { {3,2,1}, {1,2,1}, {1,1,1} };
// then pass in the initialized matrix into printMatrix()
printMatrix(X);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment