[ create a new paste ] login | about

Link: http://codepad.org/wCl65hXC    [ raw code | output | fork ]

pmg - C, pasted on May 7:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

static void printints(const void *a, size_t n) {
  const int *p = a;
  puts("`int` values in contiguous memory locations:");
  while (n--) printf("%d ", *p++);
  puts("");
}

int main(void) {
  int foo[2][2][2][2][2], base = 1000;
  size_t d0, d1, d2, d3, d4;

  srand(time(0));

  for (d2=0; d2<2; d2++) /* lines */
  for (d4=0; d4<2; d4++) /* fun   */
  for (d0=0; d0<2; d0++) /* swap  */
  for (d1=0; d1<2; d1++) /* these */
  for (d3=0; d3<2; d3++) /* for   */

  {
    base += 100 + rand() % 900;
    /* alternatively swap the array indexes */
    foo[d2][d4][d0][d1][d3] = base;
  }

  printints(foo, sizeof foo / sizeof (int));
  return 0;
}


Output:
1
2
`int` values in contiguous memory locations:
1991 2460 3115 3670 4666 4971 5836 6796 7764 7943 8312 8785 8908 9309 10085 10587 11123 11719 11836 11965 12583 13387 13667 14563 15361 15868 16510 17040 17447 18434 19370 19768 


Create a new paste based on this one


Comments: