How can I increase image size by zero padding?
I suppose the array names are not descriptive of the contents and you have simply repurposed them. To zero-pad from 8x8 to 32x32:

for (int i = 0; i &lt; 32; i++) 
    for (int j = 0; j &lt; 32; j++) 
        pspectrum[i][j] = 0;
for (int i = 0; i &lt; 8; i++) 
    for (int j = 0; j &lt; 8; j++) 
        pspectrum[i][j] = powerspectrum[i][j];


The purpose of this is that the discrete Fourier transform (DFT) of a larger image has a higher frequency resolution, so you can resolve for example the dominant frequency more accurately. It is the same as really well done interpolation in the frequency domain.