Skip to content

Instantly share code, notes, and snippets.

@ryunp
Created September 6, 2014 20:56
Show Gist options
  • Save ryunp/7cca4f4468b60b311368 to your computer and use it in GitHub Desktop.
Save ryunp/7cca4f4468b60b311368 to your computer and use it in GitHub Desktop.
/*
* File: main.c
* Author: Ryan
*
* Created on September 6, 2014, 1:01 PM
*/
#include <stdio.h>
#include <stdlib.h>
/*
* data[] is the input array
* result[][] is the output array
*
* dSize is number of data elements in data[]
* rSize is number of data elements in result[]
* rVolume is number of data elememnts in result[][]
*/
int main(int argc, char** argv) {
int debug = 1,
data[] = {1,2,3,4},
dSize = ((long)(&data+1) - (long)(&data)) / sizeof data[0], // Cast memory address to appropriate length (architecture dependant) and divide by data element size
//dSize = sizeof data / sizeof data[0], // Standard sizeof statement
rSize = 2 * dSize - 1,
result[rSize][rSize],
rVolume = ((long)(&result+1) - (long)(&result)) / sizeof (int);
//rVolume = sizeof result / sizeof result[0][0];
if (debug) { printf("data[] size: %d, result[][] volume: %d",dSize,rVolume); };
return (EXIT_SUCCESS);
}
/**
* RUN OUTPUT:
*
* data[] size: 4, result[][] volume: 49
* RUN SUCCESSFUL (total time: 23ms)
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment