c++学习打卡

#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
using namespace std;
#include<string>
//int* fun_c()
//{
//	int a = 10;
//	return &a;
//}

int* fun_c()
{
	int* p = new int(10);//用指针返回开辟的这块堆内存的编号
	return p;
}
/*int add(int a, int b)
{
	return a + b;
}*/
//void print_f(int* arr, int sz)
//{
//	for (int i = 0; i < sz; i++)
//	{
//		cout << *(arr + i) << endl;
//	}
//}
//void bubble_sort(int* arr, int sz);
//void print_f(int* arr, int sz);       //函数声明
//struct student
//{
//	int age;
//	string name;
//	int score;
//}s3;
//struct teacher
//{
//	struct student stu[5];
//	int age;
//	string name;
//};
//void print_f(struct teacher* q)
//{
//	cout << q->stu.age << q->stu.name << q->stu.score << endl;
//}
int a_g = 10;
int b_g = 10;//全局变量
const int c_a_g = 10;
const int c_b_g = 10;
int main()
{
	/*int arr[4] = { 1,2,3,4 };
	int si = sizeof(arr) / sizeof(arr[0]);
	print_f(arr,si);*/
	/*float a = 3e2;
	cout << "a= " << a << endl;
	cout << "hello world \n" << endl;
	int x, y = 0;
	cin >> x >> y;
	int sum = add(x, y);
	cout <<"total is:"<<sum<< endl;
	*/
	/*char a = 'a';
	char b = 'A';
	cout << "a= " << (int)a << endl;
	cout << (int)b << endl;*/
	/*char str[] = "hello world";//c语言式的字符类型。注意中括号以及等号后边的双引号
	cout << str << endl;
	string str2 = "hello world";//c++式的字符串类型,注意在使用时需要引用头文件#include<string>
	cout << str2 << endl;
	//常见转义字符的用法
	//1.\n
	cout << "hello world" << endl;//在c++中endl其实就是换行的功能
	cout << "hello world\n";//在c语言中常用\n转义字符换行
	//2.\t
	cout << "aaa\thelloworld"<<endl;//在c语言和c++中都有水平制表功能
	cout << "aaaa\thelloworld"<<endl;//与前面的字符共同组合八个字符大小,没有字符的用空格补充
	//3.\\
	
	//cout<<"\"<<endl;这种写法是错误的根本无法输出'\n'
	cout << "\\" << endl;//这种写法才是正确的
	bool flag = true;//布尔数据类型所占大小为1个字节,条件为真是1,否则为0.
	cout << flag<< endl;//注意在输出时不用再加入“”
	flag = false;
	cout << flag << endl;
	cout << "bool所占空间大小: " << sizeof(bool) << endl;*/
	//数据类型的输入
	//1.浮点型数据类型
	//float a = 3.14f;//此处需要在3.14后加上f否则float将会精度自动转化为double型
	//cout << "请输入浮点型数据" << endl;
	//cin >> a;
	//cout << "浮点型数据a=" << a << endl;
	2.字符型数据类型
	//char b = 'a';
	//cout << "请输入字符型数据" << endl;
	//cin >> b;
	//cout << "字符型数据b=" << b << endl;
	3.字符串数据类型
	//cout << "请给字符串类型数据赋值" << endl;
	//string arr = "abc";//特别注意在使用字符串类型时需要引用头文件#include<string>
	//cin >> arr;
	//cout << "字符串类型数据值为" << arr << endl;
	/*bool a = true;
	cout << !!a << endl;*/
	/*int a, b, c = 0;
	cout << "请输入三只小猪的体重:" << endl;
	cin >> a >> b >> c;
	if (a >b)
	{
		if (a > c)
			cout << "a小猪最胖体重是:" << a << endl;
		else if (a < c)
			cout << "c小猪最胖体重是:" << c << endl;
		else
			cout << "a小猪和b小猪都很胖体重各是\n";
		cout << "体重均是" << a << endl;
	}
	else if (a < b)
	{
		if (b > c)
			cout << "b小猪最胖体重是:" << b << endl;
		else if (b < c)
			cout << "c小猪最胖体重是:" << c << endl;
		else
		{
			cout << "c小猪和b小猪都很胖体重各是\n";
			cout << "体重均是" << b << endl;
		}
	}
	else
	{
		if (a > c)
		{
			cout << "a和b小猪都很胖\n";
			cout << "体重均是 " << a << endl;
		}
		else if (a < c)
		{
			cout << "c小猪最胖体重是:" << c << endl;
		}
		else
		{
			cout << "a,b,c小猪都很胖\n";
			cout << "体重均是:" << a << endl;
		}
		}*/
	/*int num = rand() % 100 + 1;
	int num1 = 0;
	while (num != num1)
	{
		cout << "请输入你要猜的数字:" << endl;
		cin >> num1;
		if (num1 > num)
			cout << "猜大了!" << endl;
		else if (num1 < num)
			cout << "猜小了!" << endl;
		else
		{
			cout << "猜对了是" << num1 << endl;
			break;
		}
	}	*/
//int a = 1;
//int b = 2;
//int num = a > b ? a : b;
//cout << a << endl;
//cout << num<< endl;
//int num = 100;
//int a, b, c = 0;
//int num1 = 0;
//do
//{
//	a = num % 10;
//	b = (num / 10) % 10;
//	c = (num / 100) % 10;//                        //水仙花数
//	num1 = a * a * a + b * b * b + c * c * c;
//	if (num1 == num)
//		cout << "该数是水仙花数为:" << num << endl;
//	
//	num++;
//	
//} while (num < 1000);
//int num = 1;
//int a, b = 0;
//for (num = 1; num <= 100; num++)
//{
//	a = num % 10;
//	b = num / 10 % 10;
//	if (num % 7 == 0)
//		cout << "敲桌子" << endl;
//	else if (a == 7 || b == 7)
//		cout << "敲桌子" << endl;
//	else
//		cout << "num=" << num << endl;
//}
//int i, j = 0;
//for (i = 1; i <= 10; i++)//                  //乘法口诀表
//{
//	for (j = 1; j <= i; j++)
//	{
//		cout << i << '*' << j << '=' << i * j << '\t';
//
//	}
//	cout << endl;
//}
//int arr[] = { 12,32,13,42,45 };
//cout << sizeof(arr) << endl;
//cout << sizeof(arr[0]) << endl;
//cout << "整个数组的大小为:" << sizeof(arr) / sizeof(arr[0]) << endl;
//cout << "数组首地址:" << arr << endl;
//cout << "数组首元素地址:" << (int)&arr[0] << endl;
//cout << "数组第二个元素的地址:" << (int)&arr[1] << endl;
//int arr[5] = { 200,300,250,400,350 };
//int sz = sizeof(arr) / sizeof(arr[0]);
//int max = 0;
//for (int i = 0; i < sz-1; i++)
//{
//	if (arr[i] > max)
//		max = arr[i];//五只小猪称体重
//}
//cout << "最胖的猪有:" << max << endl;
//int arr[5] = { 12,23,43,35,54 };
//int sz = sizeof(arr) / sizeof(arr[0]);
//int start= 0;
//int end = sz - 1;
//while (start< end)
//{
//	int temp = arr[start];
//	arr[start] = arr[end];
//	arr[end] = temp;
//	start++;
//	end--;//                                //数组逆置
//}
//for (int i = 0; i <= sz - 1; i++)
//{
//	cout << arr[i] << endl;
//}
//int arr[5] = { 46,23,11,31,47 };
//int sz = sizeof(arr) / sizeof(arr[0]);
//for (int i = 0; i < sz ; i++)
//{
//	for (int j = 0; j < sz - i - 1; j++)
//	{
//		if (arr[j] > arr[j + 1])
//		{
//			int temp = 0;
//			temp = arr[j];
//			arr[j] = arr[j + 1];
//			arr[j + 1] = temp;              //冒泡排序
//		}
//	}
//}
//for (int a = 0; a < sz; a++)
//	cout << arr[a] << endl;
//int arr[2][3] =
//{   {1,2,3},
//	{4,5,6}
//};
//cout << "二维数组所占元素:" <<sizeof(arr) << endl;
//cout << "二维数组第一行所占内存:" <<sizeof( arr[0])<<endl;
//cout << "二维数组第一个元素大小:" << sizeof(arr[0][0]) << endl;
//cout << "二维数组行数:" << sizeof(arr) / sizeof(arr[0]) << endl;;
//cout << "二维数组的列数为:" << sizeof(arr[0]) / sizeof(arr[0][0]) << endl;
//cout << "二维数组首元素地址:" <<(int)arr << endl;
//cout << "二维数组第一行元素地址" <<(int)arr[0] << endl;
//cout << "二维数组第二行元素首地址" << (int)arr[1] << endl;
//cout << "二维数组第一个元素地址:" << (int)&arr[0][0] << endl;
//int a = sizeof(arr) / sizeof(arr[0]);
//int b = sizeof(arr[0]) / sizeof(arr[0][0]);
//int sum = 0;
//string name[2] = { "张三","李四" };
//for (int i = 0; i < a; i++)
//{
//	for (int j = 0; j < b; j++)
//	{
//		sum += arr[i][j];
//	}
//	cout << name[i] << "的" << "成绩为:" << sum << endl;
//}
//int a = 10;
//int b = 20;
//const int* p = &a;//常量指针,指针指向可以改变,指针指向的值不可以改变
//cout << *p << endl;//指针解引用是求指针指向空间对应的值。
//p = &b;
//cout << *p << endl;
//int* const q = &a;//指针常量,指针指向不可以改变,指针执行的值可以改变
//*q = 20;
//cout << *q << endl;
//int arr[10] = { 12,43,23,45,22,31,53,13,32,41 };
//int sz = sizeof(arr) / sizeof(arr[0]);
//bubble_sort(arr, sz);
//print_f(arr, sz);
//student s1;                    //在c++中这一步的struct可以省略不写
//s1.age = 10;
//s1.name = "张三";
//s1.score = 100;                //结构体定义的三种方式,每一个人各代表一种方式
//student s2;
//s2 = { 20,"李四",150 };
//cout << "s1的年龄为:" << s1.age << " " << "s1的名字为: "  << s1.name << " " << "s1的成绩为: "  << s1.score << " " <<"\t"<< endl;
//cout << "s2的年龄为:" << s2.age << " " << "s2的名字为: "  << s2.name << " " << "s2的成绩为: "  << s2.score << " " <<"\t"<< endl;
//s3 = { 19,"王五",665 };
//cout << "s3的年龄为:" << s3.age << " " << "s3的名字为: "  << s3.name << " " << "s3的成绩为: "  << s3.score << " " <<"\t"<< endl;
//teacher a;
//a.stu.age = 10;
//a.stu.name = "hua";
//a.stu.score = 150;
//print_f(a);
//int a = 10;
//int b = 10;//局部变量
//cout << "局部变量a的地址为:" << (int)&a << endl;
//cout << "局部变量b的地址为:" << (int)&b << endl;//只要带有局部那么在内存区中就不在全局区中
//const int a_l = 10;
//const int b_l = 10;//const修饰的局部变量。
//cout << "局部变量a_l的地址为:" << (int)&a_l << endl;
//cout << "局部变量b_l的地址为:" << (int)&b_l << endl;
//static int a_q = 10;//静态变量
//static int b_q = 10;
//cout << "静态变量a_q的地址为:" << (int)&a_q << endl;
//cout << "静态变量b_q的地址为:" << (int)&b_q << endl;
//cout << "全局变量a_g的地址为:" << (int)&a_g << endl; //全局变量
//cout << "全局变量a_g的地址为:" << (int)&a_g << endl;
//cout << "c_a_g的const修饰的全局常量地址为:" << (int)&c_a_g << endl;
//cout << "c_b_g的const修饰的全局常量地址为:" << (int)&c_b_g << endl;//const修饰的全局变量为常量
//cout << "字符串常量s_a的地址为:" << (int)&"你啊哈哦啊" << endl;
//cout << "字符串常量s_b的地址为:" << (int)&"你啊哈哦啊" << endl;//字符串常量与const修饰的全局变量统称为常量
//string s_a = "你啊哈哦啊";//注意此时的s_a不属于字符串常量
//system("pause");
//	return 0;
//int* p = fun_c();
//cout << *p << endl;
//cout << *p << endl;//注意事项:不要返回局部变量的地址,栈区开辟的数据由编译器自动释放。
//cout << *p << endl;
//system("pause");
//return 0;
int* p = fun_c();
cout << *p << endl;
cout << *p << endl;
cout << *p << endl;
cout << *p << endl;
system("pause");
return 0;
}
//void bubble_sort(int* arr, int sz)
//{
//	for (int i = 0; i < sz-1; i++)
//	{
//		for (int j = 0; j < sz - i - 1; j++)
//		{
//			if (arr[j] > arr[j + 1])
//			{
//				int temp = 0;
//				temp = arr[j];              //冒泡排序
//				arr[j] = arr[j + 1];
//				arr[j + 1] = temp;
//			
//			}
//		}
//	}
//}
//void print_f(int* arr,int sz)
//{
//	for (int i = 0; i < sz; i++)
//	{
//		cout << *(arr + i) << endl;
//	}
//	
//}
//4,5,6,7

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值