c - 为什么 char 字符串中没有取消引用运算符?

标签 c dereference

假设我有两个函数:

void function1(int *ptr) {
     printf("%d", *ptr);
}

void function2(char *str) {
     printf("%s", str);
}

str 之前没有遵从运算符时,为什么 function2 可以工作?在 str 中只有 address 指向的不是我想的 value

最佳答案

Why does function2 work, when there is no deference operator before str

因为标准定义的 %s 需要一个 char *,即一个地址。

7.21.6.1

If no l length modifier is present, the argument shall be a pointer to the initial element of an array of character type. Characters from the array are written up to (but not including) the terminating null character. If the precision is specified, no more than that many bytes are written. If the precision is not specified or is greater than the size of the array, the array shall contain a null character.

关于c - 为什么 char 字符串中没有取消引用运算符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11653583/

相关文章:

c - 使用结构取消引用运算符在 C 中粘贴标记

java - Comparator compare method() int 不能解除引用

c - 如果用户什么都不输入,我如何返回 printf 语句?

c - fgets 没有使用设置的语言环境

c - 我正在尝试向每个新行添加数字

java - “int cannot be dereferenced”错误位于k = PIE.gcd(e1)

c++ - ptr->hello();/* VERSUS */(*ptr).hello();

C : Dereferencing pointer to incomplete type error

c - & 在 c 中的代码行为的输出

在 C 中使用 Luhn 算法进行信用卡验证