C语言char类型

发布时间 2023-09-26 17:11:18作者: 朵朵奇fa

 

 

#include <stdio.h>

int main () {
    char* s = "hello";
    
    
    // 字符串名字就是首地址
    printf("%x\n",s);
    
    // s是char指针,size = 4 or 8
    printf("sizeof s is %d\n", sizeof(s));
    
    // 解引用第一个地址得到的是h
    printf("%c\n",*s);
    
    // 解引用第二个地址得到的是e
    printf("%c\n",*(s+1));
    
    int i = 0;
    
    while (1){
        // 字符串结尾是'\0',  遇到结尾就结束
        if (*(s+i) == '\0'){
            break;
        }
        printf("%c\n",*(s+i));
        i++;
        
        
    }
    
    
    return 0;
}