Search
 
SCRIPT & CODE EXAMPLE
 

CPP

memset in c++

#include <cstring>
memset(a, 0, sizeof(a));
Comment

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;
Comment

memeset() in c++

// CPP Program to demonstrate that we can use memset() to
// set all values as 0 or -1 for integral data types also
#include <bits/stdc++.h>
using namespace std;
  
// Driver Code
int main()
{
    int a[5];
  
    // all elements of A are zero
    memset(a, 0, sizeof(a));
    for (int i = 0; i < 5; i++)
        cout << a[i] << " ";
    cout << endl;
  
    // all elements of A are -1
    memset(a, -1, sizeof(a));
    for (int i = 0; i < 5; i++)
        cout << a[i] << " ";
    cout << endl;
  
    // Would not work
    memset(a, 5, sizeof(a)); // WRONG
    for (int i = 0; i < 5; i++)
        cout << a[i] << " ";
}
Comment

c++ memset

memset(array,0,M*N*sizeof (int));
//2d array
Comment

memset in cpp

/* memset example */
#include <stdio.h>
#include <string.h>

int main ()
{
  char str[] = "almost every programmer should know memset!";
  memset (str,'-',6);
  puts (str);
  return 0;
}

Output: ------ every programmer should know memset!
Comment

Memset function in C++

/* memset example */
#include <stdio.h>
#include <string.h>

int main ()
{
  char str[] = "almost every programmer should know memset!";
  memset (str,'-',6);
  puts (str);
  return 0;
}
Comment

memset c++

memset(a, 0, sizeof(a)) 
memset(str, '#', sizeof(str)); 
Comment

PREVIOUS NEXT
Code Example
Cpp :: c++ pointers and arrays 
Cpp :: why return 0 in int main 
Cpp :: dangling pointer in cpp 
Cpp :: how to make a pointer point to a the last value in an array 
Cpp :: if not c++ 
Cpp :: how to sort string array in c++ 
Cpp :: Program to find GCD or HCF of two numbers c++ 
Cpp :: create vectors of vectors c++ 
Cpp :: javascript if else exercises 
Cpp :: cpp language explained 
Cpp :: define a type in c++ 
Cpp :: queue 
Cpp :: queue cpp 
Cpp :: problem category codechef solution in c++ 
Cpp :: summation of numbers using function 
Cpp :: what is a .h file in c++ 
Cpp :: how to bath without water 
Cpp :: how to run cpp in visual studio 
Cpp :: Bit Tricks for Competitive Programming c ++ 
Cpp :: Corong_ExerciseNo3 
Cpp :: C++ Detect when user presses arrow key 
Cpp :: jquery datepicker default date not working 
Cpp :: move semantics in c++ 
Cpp :: youtube to facebook link converter 
Cpp :: dinamic 
Cpp :: cpp pointer to two dimensional array 
Cpp :: C++ Converting Celsius to Kelvin 
Cpp :: Use of Scope Resolution operator for namespace 
Cpp :: for llop in c++ 
Cpp :: Diamond pattren program in C++ 
ADD CONTENT
Topic
Content
Source link
Name
5+9 =