簡體   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