#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
char *charStr;
int stringLength;
void genRandom() {
static const char alphanum[] =
"0123456789"
"!@#$%^&*"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz";
for (int i = 0; i < stringLength; ++i) {
charStr[i] = alphanum[rand() % (sizeof(alphanum) - 1)];
}
charStr[stringLength] = 0;
}
int main()
{
while(true)
{
genRandom();
cout < charStr;
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
编译时会出现问题.它会编译得很好但没有任何显示,然后程序将停止运行.所以我的问题是,这段代码出了什么问题?
例如:
typedef struct student {
int rollno;
float cgpa;
char name[20];
}Student;
Student me= {0,0}; // will intilize name with all zeros
Run Code Online (Sandbox Code Playgroud) 我没有在网上找到任何关于在 C 中创建对象时会发生什么的信息:比如它们的值被初始化或它们采用垃圾值。
#include <stdio.h>
struct temp
{
int a;
} s;
int main()
{
printf("%d", s.a);
}
Run Code Online (Sandbox Code Playgroud)
输出是:0。
那么 0 是垃圾值吗??或者这是一个未定义的行为?