forked from createme24/C-STL
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmemset.cpp
More file actions
28 lines (28 loc) · 708 Bytes
/
memset.cpp
File metadata and controls
28 lines (28 loc) · 708 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
//used to initialise array elemnts
// this is used to set all value of array(int) is either 0 or 1
//but u can set any char to string or character array
//memset(array_name,value,sizeof(array_name))
#include<bits/stdc++.h>
using namespace std;
int main(){
int arr[10];
memset(arr,0,sizeof(arr));
for(int i=0;i<10;i++){
cout<<arr[i]<<":";
}
cout<<endl;
int arr2[10];
memset(arr2,-1,sizeof(arr));
for(int i=0;i<10;i++){
cout<<arr2[i]<<":";
}
cout<<endl;
char arr3[10];
memset(arr3,'a',sizeof(arr));
for(int i=0;i<10;i++){
cout<<arr3[i]<<":";
}
return 0;
}
//why only 0 and -1
//memset() works byte by byte