See gdal_tutorial.html
for examples of gdal and c.
// assume all bands same size
nXSize = GDALGetRasterBandXSize( fifthPercentileBand );
nYSize = GDALGetRasterBandYSize( fifthPercentileBand );
printf("allocation size: %lu\n",
(unsigned long)nYSize* (unsigned long)nXSize*sizeof(uint8_t));
// Allocate space
pafScanline = (uint8_t *) CPLMalloc(nYSize*nXSize*sizeof(uint8_t));
dixScanline = (uint8_t *) CPLMalloc(nYSize*nXSize*sizeof(uint8_t));
refPixelScanline = (uint8_t *) CPLMalloc(nYSize*nXSize*sizeof(uint8_t));
/* and read the whole thing in */
GDALRasterIO(fifthPercentileBand , GF_Read, 0, 0, nXSize, nYSize,
pafScanline, nXSize, nYSize, GDT_Byte,
0, 0 );
GDALRasterIO(dixImageBand , GF_Read, 0, 0, nXSize, nYSize,
dixScanline, nXSize, nYSize, GDT_Byte,
0, 0 );
/* Create output */
hDstDS = GDALCreate( hDriver, pszDstFilename, nXSize, nYSize, 1, GDT_Byte,
papszOptions );
destBand = GDALGetRasterBand( hDstDS, 1 );