//相对于C语言 C++增加了一个bool类型 (bool类型 true 和false)其实就是整数 bool类型完全可以当作整数来用 0也可以转换成bool类型false 1可以转换成bool
//c++中的结构体的使用和c语言不大一样 结构体中可以实现功能 结构体可以实现构造函数
//在相同的作用域内,2个函数的名字,参数列表不同,就成为函数的重载 c不允许函数的重载 c++允许函数的重载
struct Student
{
int age;
double height;
char name[10];
Student (int age1 =20,double height1=10)
{
age=age1;
height=height1;
}
void study(int a)
{
std::cout<<age;
cout<<"学生的年龄是:"<<age;
cout<<"传入的参数a的值是"<<a;
}
};
int sum(int x=1,int y=2)
{
return x+y;
};
//如果某个形参没有默认值,那么它左边的参数就不能有默认值
//比如 void test(int a=20,int b)的写法是错误的
//例子如下
//int test(int x=20,int y)
//{
// return x-y;
//};
//如果函数载声明的时候设定了形参的默认值那么在定义的时候不能再给形参设定指定的默认值
//在main函数中定义的结构体只能用在main函数里面
int main(int argc, const char * argv[]) {
// insert code here...
std::cout << "Hello, World!\n";
//c++中要保证所有行参都有值
int a=sum();
cout<<a<<endl;
//c++中定义结构体变量时 struct可有可无
Student s = {};
struct Student s2 = {28,1.9};
s2.study(90);
printf("age is %d",s.age);
struct Date
{
int year;
int month;
int day;
void outPut(){
cout<<year;
};
};
Date d={2018,9,9};
d.outPut();
//.直接利用结构体变量访问结构体内部的变量和函数
//指针间接遍历访问结构体内部的成员变量和函数
Date *p=&d;
p->outPut();
return 0;
}