#include <iostream>
using namespace std;
//void func(int a = 10, int b = 60, int c = 20);
//
//void func(int a, int b, int c) {
// cout << "a is " << a << endl;
// cout << "b is " << b << endl;
// cout << "c is " << c << endl;
//}
int age = 70;
//void func(int a = 10, int b = 60, int c = age) {
// cout << "a is " << a << endl;
// cout << "b is " << b << endl;
// cout << "c is " << c << endl;
//}
//void test() {
// cout << "test()" << endl;
//}
//
//void display(int a, void (*func)() = test) {
// cout << "a is " << a << endl;
// cout << "func is " << func << endl;
// func();
//}
//void display() {
// cout << "display" << endl;
//}
void display(int a = 10, int b = 20) {
cout << "a is " << a << endl;
cout << "b is " << b << endl;
}
int main() {
display(10);
display(1);
display(2);
display(3);
display(4);
//display(50);
// 指向函数的指针
/*void (*funcPtr)() = test;
funcPtr();*/
getchar();
return 0;
}
#include <iostream>
using namespace std;
inline int sum(int a, int b);
int main() {
sum(10, 20);
getchar();
return 0;
}
inline int sum(int a, int b) {
return a + b;
}
#ifndef __OTHER_H
#define __OTHER_H
void other();
#endif // !abc
#ifndef __TEST_H
#define __TEST_H
void sum();
void minus();
#endif // !__TEST_H
#include <iostream>
using namespace std;
enum Season {
Spring,
Summer,
Fall,
Winter
};
struct Student {
int age;
};
//int age = 10;
//
//int &func() {
// //// age .....
// //int &rAeg = age;
// //return rAeg;
// return age;
//}
//void swap(int a, int b) {
// int temp = a;
// a = b;
// b = temp;
//}
//void swap(int *a, int *b) {
// int temp = *a;
// *a = *b;
// *b = temp;
//}
void swap(int &a, int &b) {
int temp = a;
a = b;
b = temp;
}
int main() {
int v1 = 10;
int v2 = 20;
swap(v1, v2);
cout << "v1 is " << v1 << endl;
cout << "v2 is " << v2 << endl;
/*func() = 30;
cout << age << endl;*/
/*int age = 20;
int &rAge = age;
rAge = 30;
int *p = &age;*/
// 定义了一个引用,相当于是变量的别名
/*int &rAge = age;
int &rAge1 = rAge;
int &rAge2 = rAge1;
rAge = 11;
cout << age << endl;
rAge1 = 22;
cout << age << endl;
rAge2 = 33;
cout << age << endl;*/
/*Season season;
Season &rSeason = season;
rSeason = Winter;
cout << season << endl;*/
/*Student stu;
Student &rStu = stu;
rStu.age = 20;
cout << stu.age << endl;*/
/*int a = 10;
int b = 20;
int *p = &a;
int *&rP = p;
rP = &b;
*p = 30;
cout << a << endl;
cout << b << endl;*/
/*int array[] = { 10, 20, 30 };
int (&rArray)[3] = array;
int *a[4];
int (*b)[4];*/
getchar();
return 0;
}
#include <iostream>
using namespace std;
//struct Student {
// int age;
//};
//int func() {
// return 10;
//}
//int sum(int *a, int *b) {
// cout << "sum(int *a, int *b)" << endl;
// return *a + *b;
//}
int sum(const int *a, const int *b) {
cout << "sum(const int *a, const int *b)" << endl;
return *a + *b;
}
int main() {
/*int age = 10;
int &rAge = age;
rAge = 20;*/
/*int v1 = 10;
int v2 = 20;
sum(&v1, &v2);
const int v3 = 10;
const int v4 = 20;
sum(&v3, &v4);*/
/*int a = 10;
int b = 20;
int *p = &b;
*p = a;
p = &a;*/
// sum(50, 60);
/*int a = 20;
int b = 30;
int age = 10; */// 4
//const double &ref = age; // 8
//const int &rAge = func();
//const int &rAge = 40;
//const int &rAge = a + b;
// 引用的本质就是指针
//int age = 10;
// rAge的指向不能改
// int & const rAge = age;
// 不能通过引用修改所指向的内容
/*const int &rAge = age;
rAge = 30;*/
// 不能通过指针修改所指向的内容
// int const *pAge1 = &age;
// 不能修改指针的指向,但是可以通过指针修改所指向的内容
// int * const pAge2 = &age;
/*const int age = 10;
const Student stu = { 20 };
Student stu2 = { 40 };
stu = stu2;
stu.age = 50;*/
/*Student stu = { 20 };
stu.age = 40;
const Student *pStu = &stu;
pStu->age = 50;*/
//int height = 20;
//int age = 10;
//// *p0是常量,p0不是常量
//const int *p0 = &age;
//// *p1是常量,p1不是常量
//int const *p1 = &age;
//// p2是常量,*p2不是常量
//int * const p2 = &age;
//// *p3是常量,p3是常量
//const int * const p3 = &age;
//// *p4是常量,p4是常量
//int const * const p4 = &age;
/*Student stu1 = { 10 };
Student stu2 = { 20 };
const Student * pStu = &stu1;
*pStu = stu2;
(*pStu).age = 30;
pStu->age = 40;
pStu = &stu2;*/
getchar();
return 0;
}