#include /* C example */ #include int main(int argc, char **argv) { size_t n; char *p; printf("How many char's do you want to allocate? "); scanf("%u", &n); /* not portable */ p = malloc(n * sizeof (char)); if (p == NULL) { fprintf(stderr, "%s: can't allocate %u char's\n", argv[0], n); return EXIT_FAILURE; } p[0] = 'A'; /* or *p = 'A'; */ p[1] = 'B'; p[2] = 'C'; /* etc. */ p[n - 1] = '\0'; /* Warning: the subscripts only go up to n - 1. */ printf("The hidden numbers are %u and %u.\n", /* unofficial; not portable */ ((size_t *)p)[-2], ((size_t *)p)[-1]); free(p); return EXIT_SUCCESS; }