You do not need to initialize the array to 0. Example:
void sawan() {
int wafer = 26;
int nof1;
if (wafer == 26) nof1 = 25;
if (wafer == 10) nof1 = 40;
const int nof = nof1;
int array[nof];
memset(array, 0, sizeof(array));
TH1F *histograms[nof];
auto c = new TCanvas("c","c",1000,1000);
c->Divide(5,5);
for (int i=1; i<=nof; i++) {
histograms[i-1] = new TH1F(Form("h%d",i),Form("h%d",i),100, -4,4);
histograms[i-1]->FillRandom("gaus",20000);
c->cd(i);
histograms[i-1]->Draw();
}
}