为您找到"
char a[3],b[ ]=”china”;a=b;printf(“%s”,a);
"相关结果约100,000,000个
a=b; 此处编译器提示a=b;这句中必须是一个可更改的左值。而数组名相当于一个指针常量,不等同于指针 将char a [3]改成char *a char *a,b []="china"; a=b; for (i=0;i<3;i++) printf ("%c",* (a+i));
Use printf With %s Specifier to Print Char Array in C The printf function in C is a versatile tool for formatting and outputting data to the console. It can manipulate input variables using type specifiers and format them accordingly. When it comes to printing character arrays, the %s specifier in printf plays a crucial role. A character array in C is essentially a sequence of characters ...
解释:首先定义了一个字符数组 a,长度为 3,又定义了一个字符数组 b,长度为 6,初始化为 "China"。 然后使用 strcpy() 函数将 b 复制到 a 中,因为 b 的长度为 6,所以 a 数组必须至少有 6 个元素才能存放完整的字符串。 最后使用 %s 格式化符输出 a 数组中的字符串。
25 %c is designed for a single character a char, so it print only one element.Passing the char array as a pointer you are passing the address of the first element of the array (that is a single char) and then will be printed : s printf("%c\n",*name++); will print i and so on ...
首页 > 试题广场 > 下面程序段() [单选题] 下面程序段() char a [3], b []="China"; a = b; printf ("%s", a);
D 结果三 题目 有下面的程序段:char a [3],b []="China";a=b;printf ("%s",a); A. 运行后将输出China B. 运行后将输出Ch C. 运行后将输出Chi D. 编译出错 答案 D .编译出错 结果四
nullc语言字符串不进行数组越界判断,因此使用%s输出,直至遇到\0结束。所以能够完全输出China,因此答案为a
china 输出字符串是以结束符 '\0'表示输出结束。 a=b表示a和b指向同一个地址,也就是字符串的起始地址是一致的,所以输出的结果和输出的b是一致的, b的a后面有一个 '\0',是自动添加上去的。所以输出结果为 china。
I define b as pointer to string: char a[] = "hello"; char *b; strcpy(&b, a); So far so good (although I don't quite understand why b=&a doesn't work, considering that both a and b are pointers). Now when I want to print the string pointed to by b, I have to use &b: printf ("%s", &b); Why do I need to give address of a pointer to printf (), in order for contents of the variable that this ...
( 单选题 ) 手机预览 c语言复习题库习题库 有下面的程序段: char a [3], b [] = "china"; a = b; printf ("%s", a) ; 则输出结果为 ( ) A、编译出错 B、运行后输出 china C、运行后输出 ch D、运行后输出 chi 答案:A 解析:数组 相关题库: c语言复习题库习题库 分享 c语言复习题库 ...