繁体   English   中英

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'

我包括使用memset的'cstring'。 这是我关注的文档: http : //www.cplusplus.com/reference/clibrary/cstring/memset/

为什么我得到这个结果? 我敢肯定这可能很明显,我只是看不到。

memset用一个未签名的char填充内存:

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.

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM