Program to allocate an array & initialize all elements to zero in C language.

We will first create a array then we will use for loop to initialize every position in array to zero. Check the program given below.

#include<stdio.h>

int main()
{
    int i,a[10];

    for(i=0;i<10;i++)                         
    a[i]=0;
//initialized array elements to zero

    for(i=0;i<10;i++)
    printf("%d ",a[i]);  //print elements of array

}

Output :

0 0 0 0 0 0 0 0 0 0 

Post a Comment

0 Comments