我想打印字符数组(作为字符串),但它在运行时显示一个空字符串
初始化:
char str1[6]= "Black";
char str2[7]= "Yellow";
Run Code Online (Sandbox Code Playgroud)
printf 语句:
printf ("%s = %d Bath\n",str1,a);
printf ("%s = %d Bath\n",str2,a);
Run Code Online (Sandbox Code Playgroud)
预期的:
Black = 150 Bath
Yellow = 150 Bath
Run Code Online (Sandbox Code Playgroud)
输出
Black = 150 Bath
= 150 Bath
Run Code Online (Sandbox Code Playgroud)
我尝试在没有大小数字的情况下进行初始化,例如char str2[]= "Yellow";
或使用 C++ cout 来显示
原始代码:
char str1[6]= "Black";
char str2[7]= "Yellow";
Run Code Online (Sandbox Code Playgroud) c ×1