初识C语言

安装VisuaI C++

根据自己学习的视频和老师使用的编辑器同步即可

C++兼容C语言,可以在这个文件里写c也可以写c++

1
https://www.runoob.com/cplusplus/cpp-environment-setup.html

快速创建项目

1、file–>new

image-20230422110834605

2、为项目取名并且放到一个合适的目录中

image-20230422111802394

3、选择Hello world程序

image-20230422111845139

4、打开源文件

image-20230422112009945

项目描述

1
2
3
4
5
6
7
8
9
10
// Test.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"//程序运行需要依赖该行代码,后面会具体解释

int main(int argc, char* argv[])//程序的入口
{
printf("Hello World!\n");//打印一句话Hello World!
return 0;
}

F7编译当前项目为.exe文件放到项目目录的Debug目录下

C:\Project\Test\Debug

image-20230422112545895

F5运行程序

image-20230422112654065

shift+F5结束程序运行

重新打开项目的时候选择workspace

image-20230422113527724

image-20230422114056981

注意断点在最后了,所以变量x是有值的

image-20230422114450524

C语言函数格式

1
2
3
4
[返回值类型] [函数名]([参数])
{
//代码,每行以;结尾
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// Test.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

void Function()
{

}

int main(int argc, char* argv[])
{
Function();

return 0;
}

空函数反汇编

切记程序必须在运行状态下,也就是F5之后才能右键找到该选项

image-20230422120013328

image-20230422120443654

vc++的F10相当于od里面的F8