C - Is it possible to insert an array into a structure? [closed]

1

A question that came to me days ago was whether it is possible to insert a matrix into a structure, I think so, but in the process of deciding to clarify it.

EXAMPLE

typedef struct matrizexemplo {
    int matriz[2][2];
}
    
asked by anonymous 07.12.2016 / 00:51

1 answer

3

Perfectly possible. Here is an example use to add two elements of this array:

#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;
}
    
07.12.2016 / 04:24