C++中cout输出字符串和字符串型指针地址值的方法以及C语言中的printf用法比较

C++中cout输出字符串和字符串型指针地址值的方法以及C语言中的printf用法比较,第1张

概述#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 = %
#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;}

总结

以上是内存溢出为你收集整理的C++中cout输出字符串和字符串型指针地址值的方法以及C语言中的printf用法比较全部内容,希望文章能够帮你解决C++中cout输出字符串和字符串型指针地址值的方法以及C语言中的printf用法比较所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1210858.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-04
下一篇 2022-06-04

发表评论

登录后才能评论

评论列表(0条)

保存