Wednesday, November 15, 2017

How to set all of the element of an array as 0 in c++ programming

Using memset keyword we can set 0 for all index of an array .

we can don  it in two different way

1 .
    int  array[5] = {0,0,0,0,0};

2 .
   #include<bits/stdc++.h>
using namespace std;
int main()
{
    int array[5];

    memset(a, 0, sizeof(a));    // This is the line where we set 0 as value for all index of the array

    for(int i=0; i<5; i++){
        cout<<" "<<array[i];
    }
    cout<<endl;

    return 0;
}

No comments:

Post a Comment

কম্পিউটার প্রোগ্রামিং শেখা কতটা গুরুত্বপূর্ণ ?

প্রোগ্রামিং কতটা গুরুত্বপূর্ণ? কম্পিউটার বিজ্ঞানের অনেক বড় একটা অংশ জুড়েই রয়েছে প্রোগ্রামিংয়ের দখল। প্রোগ্রামিং ছাড়া আমর...