C - Is it possible to insert a matrix into a structure?

Asked

Viewed 213 times

1

A question that came to me a few days ago, was whether it is possible to insert a matrix into a structure, I think so, but on the road of doubts I decided to clarify.

EXAMPLE

typedef struct matrizexemplo {
    int matriz[2][2];
}
  • 3

    Possible it is, is having some problem?

  • ah hello @bigown again! was a problem of a friend of mine, but already solved the subject, thanks anyway! :)

1 answer

3


Perfectly possible. Here is an example of using two elements of this matrix:

#include <stdio.h>

typedef struct matriz{
    int matriz[2][2];
}Matriz;

int main() {
    Matriz uma_matriz;

    uma_matriz.matriz[0][0] = 1;
    uma_matriz.matriz[1][1] = 2;

    // Printa 3 no terminal
    printf("%d\n", uma_matriz.matriz[0][0] + uma_matriz.matriz[1][1]);

    return 0;
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.