全局变量
在C++中,不允许定义多个同名的全局变量
#include <iostream>
//int g_var;
int g_var = 1;
int main(int argc, char* argv[])
{
printf("g_var = %d\n", g_var);
system("pause");
return 0;
}
struct类型
C++中的struct是一个新类型的定义声明,C语言的struct定义了一组变量的集合,C编译器并不认为这是一种新的类型
#include <iostream>
struct Student
{
char name[8];
int age;
};
int main(int argc, char *argv[])
{
Student s1 = { "Lily", 18 }; //not allow in c
Student s2 = { "Lucy", 20 };
std::cout << s1.name << s1.age << std::endl;
std::cout << s2.name << s2.age << std::endl;
system("pause");
return 0;
}
引用
#include <iostream>
int main(int argc, char *argv[])
{
int a = 10;
int &b = a;
int &c = b;
b = 11;
std::cout << "b:" << b << std::endl; //11
std::cout << "a:" << a << std::endl; //11
c = 12;
std::cout << "b:" << b << std::endl; //12
std::cout << "a:" << a << std::endl; //12
system("pause");
return 0;
}
#include <iostream>
void swap(int &a, int &b)
{
int c = 0;
c = a;
a = b;
b = c;
}
int main(int argc, char *argv[])
{
int a = 10; int b = 20;
swap(a, b);
std::cout << "a = " << a << " b = " << b << std::endl; //20 10
system("pause");
return 0;
}
[正则表达式使用简单总结](https://blog.csdn.net/fengbingchun/article/details/54835571)