Skip to content

Instantly share code, notes, and snippets.

@Et7f3
Last active October 24, 2019 14:52
Show Gist options
  • Save Et7f3/eb2b9957137c7ce1f58eb3eac590cefe to your computer and use it in GitHub Desktop.
Save Et7f3/eb2b9957137c7ce1f58eb3eac590cefe to your computer and use it in GitHub Desktop.
strange sizeof behaviour
/******************************************************************************
Online C Compiler.
Code, Compile, Run and Debug C program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <stdio.h>
void print(size_t h, size_t w, size_t prof, char tableau[h][w][prof])
{
printf("%ld, %ld, %ld, %ld\n", w * h * prof * sizeof(tableau[0][0][0]), sizeof(tableau[0]), sizeof(tableau[0][0]), sizeof(tableau));
for (int i = 0; i < h; ++i) {
printf("New dimension:\n");
for (int j = 0; j < w; ++j) {
for (int k = 0; k < prof; ++k) {
printf("%d", tableau[i][j][k]);
}
puts("");
}
}
}
int main()
{
const size_t h = 2, w = 2, prof = 3;
char tableau[2][2][3] = {
{
{0, 1},
{2, 3},
},
{
{4, 5},
{6, 7},
}
};
print(h, w, prof, tableau);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment