C++Primer第五版第三章练习3.37

/*
练习3.37:
下面的程序是何含义,程序的输出结果是什么?
const char ca[]={'h', 'e', 'l', 'l', 'o'};
const char *cp=ca;
while(*cp){
	cout<<*cp<<endl;
	++cp;
}
答:ca是一个常量字符数组,但是结尾没有含空字符'\0',
cp是一个指向常量字符的指针,初始化值为一个常量字符数组第一个元素的地址
while循环的条件是:cp指向的字符不为空,循环体:先输出cp指向的字符,cp向前移动,指向下一下字符。
程序不仅输出字符数组的字符,还向接着输出别的内容,直到遇到空字符才停止输出。
*/
#include <iostream>
#include <string>
#include <typeinfo>
#include <vector>
#include <cctype>
#include <cstring>
using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;
int main()
{
	const char ca[]={'h', 'e', 'l', 'l', 'o'};
	const char *cp=ca;
	while(*cp){
		cout<<*cp<<endl;
		++cp;
	}
	cout<<endl;
	return 0;
}

  • 6
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值