小编vga*_*997的帖子

为什么C中的指针可以在不取消引用的情况下打印其内容?

我创建了一个程序,其中我注意到两件事

  1. 我使用指针的地址来打印整个单词,它可以工作,但是当我用 *s 替换 s 时,它不起作用(为什么会发生这种情况?)(我在 printf 中使用地址而不是 *s 内容)
  2. 当我使用指向指针的指针来打印字符时,我无法打印任何内容(我的意思是当我用 %c 替换 %s 时)

我的代码:

#include<stdio.h>


int main ()
{
    char str[10]="PinkFloyd";
    char *s;
    char **s1;
    
     s=&str[0];
     
     s1=&s;
     
     printf("the word is using pointer to pointer %s",*s1); //why if I used %c does not print the first character 
     printf("\n");
     printf("the word is using s pointer %s",s); // why if I had replaced with *s does not print anything
    
    
    
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c arrays string pointers

2
推荐指数
1
解决办法
1256
查看次数

标签 统计

arrays ×1

c ×1

pointers ×1

string ×1