memset is a C standard library function that sets the first N bytes of the block of memory to the specified value (interpreted as an unsigned char)
Questions tagged [memset]
502 questions
-4
votes
1 answer
Is it legal to use memset() function on `const` array?
In the following code, elements of the const array are cleared by the memset function.
#include
#include
int main() {
const int a[3] = {1, 2, 3};
memset(a, 0, sizeof(a));
printf("%d %d %d\n",a[0],a[1],a[2]);
…

msc
- 33,420
- 29
- 119
- 214
-4
votes
2 answers
Simple matter about Memset in C
I am a begginner at C so please bear with me;
I am aware that i can make an array statement as *c or c[];
My question is about memset:
char str[] = "hello!";
memset (str,'-',2);
puts (str);
Works fine.
But:
char *str = "hello!";
memset…

Mondometal
- 1
- 1
-4
votes
1 answer
Behaviour of memset in C
Consider the below structure
struct A
{
int len;
int wid;
int size;
};
void main()
{
struct A var;
memset(&var,10,sizeof(struct A));
printf("value of len is %d\n",var.len);
}
When I run the program, I was expecting that all…

vivek
- 467
- 2
- 6
- 18
-5
votes
1 answer
how to ue memset to set a particular column of 2D array
Guys i have a array xd[2][10000] like that now i
i want to run a loop from 0 to 10000
now i want that when i=0 the value of xd array from 0 to 10000 becomes 0
next time when i=1 the value from xd[0][1] to xd[0][10000] becomes 1 similary when i=2…

rightguy
- 17
- 2
- 8
-7
votes
2 answers
memset after malloc
I have three lines (version) of a linux product. V1 works fine in the customer. V2 and V3
crashed and the fix seems to be a memset call after a malloc call.
What is the deeper explanation on this topic? Why memset resolved the issue?

cateof
- 6,608
- 25
- 79
- 153
-7
votes
1 answer
What causes the segmention fault in this memset()?
So I know a seg fault occurs but I can't pinpoint the internal logic behind it.
I believe that it is because there was a failure to initialize a pointer before accessing it.
But what would trigger this in terms of memory.
ex code:
#include…

kadash12
- 19
- 6
-8
votes
4 answers
memset causes "vector iterators incompatible" error
Currently working on my DirectX game and using memset(0) (or ZeroMemory macro in VS if you wish) in constant buffers constructors to initialize all values with zeros and it works just fine. Problem occurs when I accidentally tried to initialize some…

user2050353
- 5
- 1