c - printf如何处理字符串

标签 c string pointers

看下面的代码

char *p="bayant";  // char pointer
char str[ ] = "bayant"; // char array
printf("%s",p);//here we are passing pointer
printf("%s",str);//here we are passing strings base address

但是当我们对指针和字符串使用相同的格式时,它是如何工作的呢?

最佳答案

%s 转换规范需要一个 char * 参数。

在第二种情况下,您有一个 char 参数数组,但是 C 规则将(少数情况除外)char 类型数组的表达式转换为类型 char *.

关于c - printf如何处理字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21917408/

相关文章:

java - 我尝试从键盘添加字符串后,数组列表返回空列表

python - 列表的列,将列表转换为字符串作为新列

c - 如何在 C99 中迭代 char*?

c - 在C函数中返回struct

c++ - 这可能吗?(C++)

c - ASN1 UTF-8 字符串解码

c - 链表的冒泡排序

c - 迭代指向 K&R 中指针数组的指针

c - 如何检索大文件

c++ - 热获取范围内的随机日期