看下面的代码
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/