下面的程序在C语言中编译得很好,有警告,但是在C++中编译失败。为什么?原因何在?
#include <stdio.h>
int main(void)
{
char a[5]="Hello";
a[0]='y';
puts(a);
for(int i=0;i<5;i++)
printf("%c",a[i]);
return 0;
}
警告:
Warning:[Error] initializer-string for array of chars is too long [
我正在把我的c++程序转换成c,它是一个简单的阶乘函数。我在c++程序中使用了一种有趣的方法,以便在函数每次调用自己时,对它的空间越来越小。这就是它的样子:
cout << setw( number * 3 ) << "" << "number is: " << number << endl;
它不像我所希望的那么容易翻译成c。我的想法(可能是不正确的)是
char c = "";
printf( "%*c number is: %lo\n", number * 3, c
Problem:虽然我声明了两个字符字符串,它们的内容是相同的,但是输出是不同的。
#include <stdio.h>
int main(void)
{
/* Initialization of two different array that We deal with */
char arr1[10]={'0','1','2','3','4','5','6','7','8','9'};
我在c++中玩char数组,并编写了以下程序:
int main()
{
char text[] = { 'h', 'e', 'l', 'l', 'o' }; //arrays initialised like this
//will have a size of the number
//of elements that you s