memset c++
C++
// CPP program to illustrate memset
//works with var adresses ,basically characters but limit its use to -1 and 0 in int
#include <cstring>
#include <iostream>
using namespace std;
int main()
{
char str[] = "geeksforgeeks";
memset(str, 't', sizeof(str));
cout << str;
return 0;
}
output:
tttttttttttttt
/* 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!// memset syntax
void * memset ( void * ptr, int value, size_t num );#include <bits/stdc++.h>
using namespace std;
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] << " ";
}
Also in C++:
- Title
- c++ give options
- Category
- C++
- Title
- nearest integer rounding in c++
- Category
- C++
- Title
- how to print cpp
- Category
- C++
- Title
- sieve of eratosthenes c++
- Category
- C++
- Title
- what is difffrence between s.length() and s.size()
- Category
- C++
- Title
- how to avoid tle in c++
- Category
- C++
- Title
- c++ sql
- Category
- C++
- Title
- Find a element in a map C++
- Category
- C++
- Title
- minimum swaps to sort an array
- Category
- C++
- Title
- char **
- Category
- C++
- Title
- object reference not set to an instance of an object c#
- Category
- C++
- Title
- C++ remove element from set
- Category
- C++
- Title
- c++ read matttrix from text file
- Category
- C++
- Title
- what is difference between ciel and floor
- Category
- C++
- Title
- getline in c++
- Category
- C++
- Title
- c++ loop through array
- Category
- C++
- Title
- is not a nonstatic data member or base class of class
- Category
- C++
- Title
- insert function in c++ vector
- Category
- C++
- Title
- memset
- Category
- C++
- Title
- queue stl c++
- Category
- C++
- Title
- getline not working c++
- Category
- C++
- Title
- c++ get last element in vector
- Category
- C++
- Title
- how to find length of string in c++
- Category
- C++
- Title
- Html tab
- Category
- C++
- Title
- queue c++
- Category
- C++
- Title
- min heap priority queue c++
- Category
- C++
- Title
- set lower bound c++
- Category
- C++
- Title
- c++ print one line to console instead of multiple
- Category
- C++
- Title
- for c++
- Category
- C++
- Title
- how to print for limited decimal values in c++
- Category
- C++
- Title
- check for bst
- Category
- C++
- Title
- what is meaning of 64 bit integer in c++
- Category
- C++
- Title
- getting a random letter in c++
- Category
- C++
- Title
- pair in c++
- Category
- C++
- Title
- free or delete in c++
- Category
- C++
- Title
- git branch in my bash prompt
- Category
- C++
- Title
- container class in c++
- Category
- C++
- Title
- c++ functions
- Category
- C++
- Title
- best fit algorithm
- Category
- C++
- Title
- how to switch to another branch in git
- Category
- C++
- Title
- transpose matrix eigen c++
- Category
- C++
- Title
- fast input output in c++
- Category
- C++
- Title
- primeros numeros primos
- Category
- C++
- Title
- primos menores que
- Category
- C++
- Title
- initialize map c++
- Category
- C++
- Title
- c++ find prime numbers
- Category
- C++
- Title
- appending a double to a string c++
- Category
- C++
- Title
- convert decimal to binary in c++
- Category
- C++
- Title
- maximum subarray sum equal with K in c++
- Category
- C++
- Title
- substr c++
- Category
- C++
- Title
- iterate const vector
- Category
- C++
- Title
- c++ char print width
- Category
- C++
- Title
- How to read a file in in C++
- Category
- C++
- Title
- how to iterate trough a vector in c++
- Category
- C++
- Title
- maximum subarray sum in c++
- Category
- C++
- Title
- how to measure program run time in c++
- Category
- C++
- Title
- how to read a comma delimited file into an array c++
- Category
- C++
- Title
- residuo en lenguaje c
- Category
- C++
- Title
- how to output to console c++
- Category
- C++
- Title
- translate
- Category
- C++
- Title
- what are the different ways to traverse a binary tree
- Category
- C++
- Title
- remove from unordered_set c++
- Category
- C++
- Title
- visual studio 2019 read and write text file c++
- Category
- C++
- Title
- never gonna give you up lyrics
- Category
- C++
- Title
- c++ program how to let the user choose different game modes
- Category
- C++
- Title
- decimal to hex cpp
- Category
- C++
- Title
- counting valleys hackerrank solution in c++
- Category
- C++
- Title
- how to delete something in an array c++
- Category
- C++
- Title
- substr in c++
- Category
- C++
- Title
- clear file before writing c++
- Category
- C++
- Title
- min coin change problem dp
- Category
- C++
- Title
- length of array in cpp
- Category
- C++
- Title
- qt make widget ignore mouse events
- Category
- C++
- Title
- loop through array c++
- Category
- C++
- Title
- arduino falling edge
- Category
- C++
- Title
- c++ how to skip the last element of vector
- Category
- C++
- Title
- how to check type in c++
- Category
- C++
- Title
- Operator overloading in C++ Programming
- Category
- C++
- Title
- how to turn int into string c++
- Category
- C++
- Title
- euler's totient function c++
- Category
- C++
- Title
- string to vector c++
- Category
- C++
- Title
- iterate 2d array c++
- Category
- C++
- Title
- lambda operator in c++
- Category
- C++
- Title
- file format not recognized treating as linker script c++
- Category
- C++
- Title
- phph date
- Category
- C++
- Title
- c++ string to integer without stoi
- Category
- C++
- Title
- string comparison in c++
- Category
- C++
- Title
- how to compile opencv c++ in ubuntu
- Category
- C++
- Title
- variant hold type
- Category
- C++
- Title
- sum of two numbers c++
- Category
- C++
- Title
- how to read and write in a file c++
- Category
- C++
- Title
- c++ class inheritance
- Category
- C++
- Title
- hashset in c++
- Category
- C++
- Title
- power in c++
- Category
- C++
- Title
- new class * [] c++
- Category
- C++
- Title
- how to remove maximum number of characters in c++ cin,ignore
- Category
- C++
- Title
- floor() in c++
- Category
- C++
- Title
- what is order in of preeendence in float, int, char, bool
- Category
- C++
- Title
- c++ constructor
- Category
- C++
- Title
- c++ files
- Category
- C++