有C基础学习C++第一天(基础语法)

1.输入的代码与c不同,c:printf;
2.科学计数法
3.C风格字符串,用数组,不能用string

#include <iostream>
using namespace std;
#define Day 7
int main() {
	//输入的代码与c不同,c:printf
	cout << "hello C++" << Day << "天" << endl;//hello C++7天
	const double pi = 3.14;
	float f1 = 3.15f;//float后加值+f
	int a = 110;
	cout << a  << endl;
	//sizeof 数据类型长度
	cout << sizeof(a) << endl;

	//科学计数法
	float f2 = 3e3;//3*10^3
	float f3 = 3e-3;//3*0.1^3

	cout << f2<< f3 << endl;
	
	//C风格字符串,用数组,不能用string
	char c1[] = "aabbcc";
	//C++风格字符串
	string c2 = "aabbcc";
	cout << c1 << "  "<< c2 << endl;



	system("pause");
	return 0;
}      

4.c++的输入

#include <iostream>
using namespace std;

int main() {
	//输入
	int a = 0;
	cout << "给a赋值" << endl;
	cin >> a;
	cout << a << endl;

	system("pause");
	return 0;

}

5.++x,x++
6.continue语句,break语句

#include <iostream>
using namespace std;

int main() {
	int a = 10;
	int b = 10;
	//++x,x++
	int a1 = ++a * 10;//先变量+1,再表达式运算
	cout << a1 << endl;//110
	int b1 = b++ * 10;//先表达式运算,再变量+1
	cout << b1 << endl;//100

	//continue语句
	for (int i = 0; i < 100; i++) 
	{
		//如果是奇数输出,偶数不输出
		if (i % 2 == 0)
		{
			continue;//跳过这个循环,到下一个循环
		}
		cout << i << endl;//输出0~100的奇数
	}
	cout << "****************" << endl;

	//break语句
	for (int j = 0; j < 100; j++)
	{
		//如果是奇数输出,偶数不输出
		if (j % 2 == 0)
		{
			break;//跳出整个循环
		}
		cout << j << endl;//不输出
	}


	system("pause");
	return 0;
}

7.goto语句

#include <iostream>
using namespace std;

int main() {
	//goto语句
	cout << "1.xxxx" << endl;
	cout << "2.xxxx" << endl;
	goto FLAG;
	cout << "3.xxxx" << endl;
	cout << "4.xxxx" << endl;
	FLAG://:确认标记
	cout << "5.xxxx" << endl;


	system("pause");
	return 0;

}

输出结果

1.xxxx
2.xxxx
5.xxxx
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值