问题
我有一个使用malloc
初始化的array
。当数组被初始化时,如果我打印出array
的一个元素而不替换任何值,那么它会为我返回值-842150451
- 我假设它不会总是返回相同的值(我相信这是将地址转换为整数)。如何检查数组中的元素是否为地址?
我想能够检查一个数组的索引是否是一个地址。如果是这样,我希望能够用一个整数替换该值,或者乘以它。
例如:
if(array[0] == address) Then
array[0] = 5; //Replaces the value of the address with a random integer.
else
array[0] *= 3; // Otherwise, if the element at index 0 is not an address, then multiply the number by an arbitrary integer.
这是可能的吗?
不,这是不可能的。一点也不。 –
malloc不会初始化分配的内存。通过访问内存获得的所有内容都是垃圾。你看到的'-842150451'是一些随机值。你的意思是什么? –
我可以检测它是否是垃圾?如果它是垃圾,那么改变它的值? – Baleroc