1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | /* vim: set tabstop=4 shiftwidth=4 fileencoding=utf-8 noexpandtab: */
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
int main(int argc, char *argv[]) {
int a[3] = {0, 0, 0}; // fun fact: int a[3] = {0}; // special case
size_t a_ct = sizeof(a) / sizeof(a[0]); // doesn't work for heap or ..* types
// a_ct == 3
int i = 10;
assert(i < a_ct && i >= 0); // please CRASH if I try to write out of bounds
int n = a[i];
return EXIT_SUCCESS;
}
|
© Copyright 2016 Alexander J. Quinn This content is protected and may not be shared, uploaded, or distributed.