Questions tagged [memset]

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)

502 questions
-2
votes
1 answer

explain the functioning of memset(arr, 10, n*sizeof(arr[0]))?

I call this function: memset(arr, 10, n*sizeof(arr[0])) I have this output: 168430090 168430090 168430090 168430090 168430090 168430090 168430090 168430090 168430090 168430090 Why?
-2
votes
2 answers

Segmentation fault (core dumped) with memset in char pointer in C++

I have two version of code. One works and the other doesnot. Working code is a follows : int main() { int i; char str[] = "Hello World"; std::cout<<"The string value before memset is : "<
nzy
  • 854
  • 2
  • 15
  • 28
-2
votes
2 answers

Memset with assignment

I have a problem : "Multiple test (t test), each test prints all strings with length N and contains exactly H numbers 1." Here is my code: #include #include using namespace std; typedef long long LL; LL t,N,H; LL…
Duck
  • 15
  • 1
  • 3
-2
votes
1 answer

Why memset function doesn't work?

Why memset function doesn't work inside c++ function with char pointers? void change(char* input){ memset(input, 'a', strlen(input)); } int main(){ char* p = "foo"; cout << p << endl; change(p); cout << p << endl; }
-2
votes
1 answer

Hardfault exception when calling memset on STM32

Starting up a STM32 i try to allocate memory for a struture pointed to by a pointer. TLxbEvents *LxbEvents memset((void*)LxbEvents, 0, sizeof(TLxbEvents)); Looking into the disassembly, it crashes always on the line STMCS r0!,{r2-r3,r12,lr} I…
Aeonos
  • 365
  • 1
  • 13
-2
votes
1 answer

using memset to initialise the int array

#include using namespace std; int main() { int arr[1010]; memset(arr,1,sizeof(arr)); cout<
-2
votes
1 answer

Use of memset to prevent ''variable-sized object may not be initialized'

I am trying to set values to a 2D array (envisage a game board or a some grid) using the code below but I receive 'variable-sized object may not be initialized' error. I tried solving it using memset but to no avail. Many thanks and some hints would…
idol2k
  • 5
  • 4
-2
votes
1 answer

What's the difference between these two memset?

int color[1001][1001]; int m,n; m=10; n=10; memset(color,0,sizeof(color)); memset(color,0,sizeof(color[0][0])*m*n ); What's the difference between these two memset statements? Any answer will be highly appreciated. Thanks in advance.
cola
  • 12,198
  • 36
  • 105
  • 165
-2
votes
4 answers

memset on vector is making its size 0

I was trying to clear all data in a vector without changing its size using memset. But after memset operation size of vector becomes 0. Here is the exact code: std::vector
SS306
  • 157
  • 1
  • 3
  • 9
-2
votes
1 answer

Passing byte[] as IntPtr by PInvoke to memset

I need to pass a byte array to memset, which due to P/Invoke clunkiness takes IntPtr. Tested by hand, it works, but I am seeking theoretical confirmation. Is this method correct? [DllImport("msvcrt.dll", EntryPoint = "memset", CallingConvention =…
ArekBulski
  • 4,520
  • 4
  • 39
  • 61
-2
votes
1 answer

char var[] = {0}; and char var[1]; are equivalent in C?

what this line will do? char var[] = {0}; Is this equivalent to the following? char var[1]; memset(var, 0, NULL);
Arun
  • 2,247
  • 3
  • 28
  • 51
-3
votes
2 answers

C++, recreate memset with pointers and address of operators

tl;dr; How to reproduce memset with basic c++? I am trying to figure out how memset works , and to see if I can reproduce it within normal c++ using pointers and address. This is what I've got so far. void test_memset( void * origin, uint8_t…
Danilo
  • 1,017
  • 13
  • 32
-3
votes
2 answers

How long does memory written with memset() stay in memory without calling free()?

On Linux. Hi. I'm sure there are many factors involved where the OS simply garbage-dumps memory allocated with memset() without calling free(), but I was wondering if anyone has a good estimation on this? That's really all I want to know. There is…
Tdizzle
  • 53
  • 8
-3
votes
1 answer

Why is memset causing problem despite being used on built-in types?

I am very new to C++ and was making a submission to this problem on Codeforces and suddenly found that using memset() was causing Wrong answer to one of the test cases. Here is the test case: Input: 4 4 3 3 3 5 Participant's output NO Jury's…
asn
  • 2,408
  • 5
  • 23
  • 37
-3
votes
5 answers

C, memset a double array failed

I want to declare a double type array dynamically, so here is my code void function(int length, ...) { ... double *a = malloc(sizeof(double) * length); memset(a, 1, sizeof(double) * length); for (int i = 0; i < length; i++) { …
GoingMyWay
  • 16,802
  • 32
  • 96
  • 149
1 2 3
33
34