C++中cout输出字符串和字符串型指针地址值的方法以及C语言中的printf用法比较
#include <iostream> using namespace std; #include <stdio.h> int main() { char *pstr = "china"; char *qstr = "america"; char *q = "adf"; char * s; s = "hello"; printf("pstr = %p\n", pstr); /*输出为字符串起始地址值*/ /*由于C++标准库中I / O类对 << 操作符重载,因此在遇到字符型指针时会将其当作字符串名来处理,输出指针所指的字符串。 https://blog.csdn.net/u013467442/article/details/43666955 */ cout << "pstr = " << pstr << endl; /*输出为字符串*/ printf("pstr = %s\n", pstr); /*输出为字符串*/ cout << "qstr = " << qstr << endl; cout << "q = " << q << endl; cout << "s = " << s << endl; printf("s = %p\n", s); return 0; }
相关推荐
lpkwxl 2020-06-17
fengjing81 2020-06-06
lynjay 2020-06-02
ericasadun 2020-03-06
Android开发CXY 2020-11-11
RealJianyuan 2020-06-14
pbyanglove 2020-06-09
徐建岗网络管理 2020-06-09
wujingsheng0 2020-05-16
吴小伟 2020-05-09
sillion 2020-05-03
xiaobater 2020-05-01
ericasadun 2020-04-26
lynjay 2020-04-26
choupiaoyi 2020-04-26