Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

memset in cpp


//memset ( variable name , values , sizeof ( variable name ) );
//
//Memset ( ) function Is used to fill a block of memory with a particular value(0 and -1)

// problem 1.
    /*int a[10]={0};
    cout<<a[5]<<endl;

    int b[10]={21};  // method wrong ... and luckily valid for only 0 (zero )
    cout<<b[5]<<endl;  */

    // problem 2.
   /* int n ; cin>>n;
    int a[n]={0};
    cout<<a[5]<<endl; */

    // solution of these problem
    // memset ()
    int n;
    cout<<"Input the size of array"<<endl;
    cin>>n;
    int a[n]; // block name --- a
    memset(a,0 ,sizeof(a));  // value --> 0 & -1
    cout<<a[4]<<endl;

    int val[9];
    memset(val, -1 , sizeof(val));
    for(int i=0;i<9;i++)
    {
        cout<<val[i]<<" ";
    }
    cout<<endl;


    char str[] = "friedchicken";
    memset(str, 't', sizeof(str));

    cout << str<<endl;
 
PREVIOUS NEXT
Tagged: #memset #cpp
ADD COMMENT
Topic
Name
1+6 =