notes/snippet/cpp/test_array.c

30 lines
671 B
C

#include <stdio.h>
#include <stdlib.h>
typedef struct Node {
int value;
int digit[1];
} Node;
int main(int argc, char *argv[]) {
int a[1];
Node *n;
int len = 100;
a[0] = 0;
printf("%d\n", a[0]);
// this code runs when compiled by gcc
printf("%d\n", a[-1]);
printf("%d\n", sizeof(Node));
n = (Node *)malloc(sizeof(Node) + sizeof(int) * len);
free(n);
/**
* Value of 2^17 is 131072
* Value of 2^27 is 134217728
* Value of 2^22 is 4194304
*/
printf("Value of 2^17 is %d\n", 1 << 17);
printf("Value of 2^27 is %d\n", 1 << 27);
printf("Value of 2^22 is %d\n", 1 << 22);
return 0;
}