栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

C++入门(Visual studio)

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

C++入门(Visual studio)

一,基础语法 1.1运行一个程序的步骤
  1. 创建项目


  2. 创建文件:源文件中添加新建项,在选中C++文件(.cpp)

  3. 编写代码

#include
using namespace std;
int main()
{
	cout << "hello world" << endl;
	system("pause");
	return 0;
}
  • 运行程序
1.2注释
  • 单行注释
int main()//单行注释
  • 多行注释
1.3变量
  • 变量存在的意义:方便管理内存空间如将变量a指向某空间,操作时只需要使用a来操作,代替了16进制空间编号。
  • 创建语法:数据类型 变量名=变量初始值
	int a = 10;//创建变量
1.4常量
  • 用于记录程序中不可更改的数据
  • 两种定义方法:
  • (1)#define 常量名 常量值
  • (2)const关键字修饰的变量(通常定义在函数体里面):const 数据类型 常量名 =常量值
#include
using namespace std;
#define day 7//宏常量
int main()//单行注释
{
	cout << "hello world" << endl;
	int a = 10;//创建变量
	const int b = 5;//关键字修饰的变量
	system("pause");
	return 0;
}
1.5sizeof关键字
  • 作用:统计数据类型/变量所占内存大小
  • 语法:sizeof(数据类型/变量)
#include
using namespace std;
#define day 7//宏常量
int main()//单行注释
{
	cout << "hello world" << endl;
	int a = 10;//创建变量
	const int b = 5;//关键字修饰的变量
	cout << "变量a所占内存大小:" << sizeof(a) << endl;
	system("pause");
	return 0;
}

1.6C++输出语句endl与ends
  • endl表示end of line此行输出结束并换行
  • ends表示输出结束后空一格
#include
using namespace std;
#define day 7//宏常量
int main()//单行注释
{
	cout << "hello world" << ends;//输出结束空格
	cout << "变量a所占内存大小:" << sizeof(a) << endl;//输出结束换行

	int a = 10;//创建变量
	const int b = 5;//关键字修饰的变量
	
	system("pause");
	return 0;
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1030051.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号