memset 将 -1 放入我的数组中,而不是我指定的值,这是怎么回事
memset is placing -1 into my array instead of the value I specified, what is going on?
int * best = new int[numNodes];
memset(best,numeric_limits<int>::max()/2,numNodes*sizeof(int));
int test = numeric_limits<int>::max()/2;
打印出数组给我一个全部 -1 的数组。打印出int"test"给了我正确的"1073741823"值
我包括"cstring"用于使用内存集。这是我关注的文档:http://www.cplusplus.com/reference/clibrary/cstring/memset/
为什么我会得到这个结果?我敢肯定这可能是显而易见的事情,我只是没有看到它。
memset 用一个无符号字符填充内存:
void *memset(void *DST, int C, size_t LENGTH);
This function converts the argument C into an unsigned char and fills the
first LENGTH characters of the array pointed to by DST to the value.
相关文章:
- 使用递归的数组的最小值.这是怎么回事
- 我不小心调用了一个没有自己类对象的成员函数.但这是怎么回事呢
- 我使用 OpenMP 的线程越多,执行时间就越长,这是怎么回事?
- qsort 不适用于我的 impl 中的浮点类型。怎么了?
- R 中的算术在数字上比整数更快。这是怎么回事?
- 我的代码运行良好,但现在当尝试将其制作成模板时,我遇到了许多看似无关的错误。这是怎么回事?
- 在变量名后声明带有 () 的非内部类型与不使用变量名的行为不同。即 std::map<int,char>x(); - 这是怎么回事?
- 对我的 c++ 金字塔分配进行小调整?我应该怎么做?
- 我必须输入我的名字才能输入我的资源,我该怎么做
- 我怎么知道我最后的指示
- 传递引用C++,指针的向量.这是怎么回事?
- 我的程序怎么了?(C )
- Sublime上的EasyClangComplete是怎么回事?
- 重复输出的类型是怎么回事,它如何区分迭代次数和 Ascii 代码?
- 我怎么知道我的服务器是否在一段时间内没有连接
- 我的记忆是怎么回事?
- 我怎么知道我的数组在缓存中
- memset 将 -1 放入我的数组中,而不是我指定的值,这是怎么回事
- 令我惊讶的是,这段代码可以正确编译和执行。这是怎么回事?
- 我的静态函数header和.cpp是怎么回事?仅在标头中定义时运行