c语言—指针基础(4:字符串常见定义方式)

时间:2022-09-27 01:44:29

字符串常见定义方式: char * = "hello";

 #include "stdafx.h"

int main() {
char str[] = { 'a','b','c','d','\0' };
char *p = str;
char *q = &str[0];
printf("p:%#x\n",p); //%#x 打印十六进制地址
printf("p:%s\n", p); //%s 打印字符串
printf("q:%#x\n", q);
printf("q:%s\n", q);
printf("str:%#x\n",str);
printf("str:%s\n", str);

//可以定义char *m = "hello";
char sb[] = "hello";
char *m = &sb[0];
m = sb;

return 0;
}

c语言—指针基础(4:字符串常见定义方式)
c语言—指针基础(4:字符串常见定义方式)