Skip to main content
6 of 6
Commonmark migration

C

sizeof(char[n][n])

It works up to INT_MAX in constant time and without memory allocation.

Example:

#include <stdio.h>
#include <limits.h>
int main(){
    for( int n=0 ; n<10 ; n++ ){
        printf("%d: %ld\n", n, sizeof(char[n][n]));
    }
    int n = INT_MAX;
    printf("%d: %ld\n", n, sizeof(char[n][n]));
}

displays

0: 0
1: 1
2: 4
3: 9
4: 16
5: 25
6: 36
7: 49
8: 64
9: 81
2147483647: 4611686014132420609
Florian F
  • 591
  • 4
  • 9