相关疑难解决方法(0)

内核将内存归零?

我正在使用Debian挤压并注意到内存始终为零.这是Linux发行版中的新功能吗?前段时间,我相信我可以使用puts()并输出垃圾.

我多次运行这个测试程序,但评论的结果总是一样的.(我在sysctl.conf中有randomize_va_space = 2,所以我知道每次运行时都会使用不同位置的内存.)


char *a = malloc(50000000);
a[49999999] = '\0';
puts(a); // it outputs nothing since all are zeroes
printf("%p\n", a);
if(a[5000] == '\0') // this condition is always true
{
    puts("It is a nul char.");
}
Run Code Online (Sandbox Code Playgroud)

是否有可能使系统内存不为零?这个Debian挤压安装有哪些选项可以激活始终为零内存?

c memory-management linux-kernel

11
推荐指数
3
解决办法
6406
查看次数

如何解决“条件中的变量声明必须具有初始化程序”

我正在编写一个计算用户输入的元音数量的程序,但它给我的错误是“条件中的变量声明必须具有初始化程序”。您如何解决?

#include <iostream>
using namespace std;

int isVowel(char c) 
{
  char Vowels[] = {'A', 'E', 'I', 'O', 'U', 'a', 'e', 'i', 'o', 'u'};
  if (c in Vowels)
    return true;
}

int main()
{
  int n;
  int numVowel = 0;
  char c;

  cin >> n;

  for (int i = 0; i < n; ++i)
  {
    cin >> c;
    if (isVowel(c))
      numVowel++;
  }

  cout << "Number of vowels = " << numVowel << endl;

  return 0;
}
Run Code Online (Sandbox Code Playgroud)

c++ c++11

1
推荐指数
1
解决办法
228
查看次数

标签 统计

c ×1

c++ ×1

c++11 ×1

linux-kernel ×1

memory-management ×1