/* struct类型的加强: C语言的struct定义了一组变量的集合,C编译器并不认为这是一种新的类型 C++中的struct是一个新类型的定义声明 struct 关键字增强 class 关键字完成的功能一样,也可以用public/protected关键字 区别后面介绍 抛砖 */ #if 1 struct Teacher { public: int age; protected: char name[32]; }; void test() { Teacher t1;//c++ 可以不用写struct关键字 struct Teacher t2;//c 必须写上struct关键字 t1.age = 30; t2.age = 10; printf("hello...\n"); } #endif /* C++中所有的变量和函数都必须有类型 C语言中的默认类型在C++中是不合法的 函数f的返回值是什么类型,参数又是什么类型? 函数g可以接受多少个参数? */ /* //更换成.cpp试试 f(i) { printf("i = %d\n", i); } g() { return 5; } int main(int argc, char *argv[]) { f(10); printf("g() = %d\n", g(1, 2, 3, 4, 5)); getchar(); return 0; } */ 所有的变量和函数都必须有类型 在C语言中 int f( );表示返回值为int,接受任意参数的函数 int f(void);表示返回值为int的无参函数 在C++中 int f( );和int f(void)具有相同的意义,都表示返回值为int的无参函数 C++更加强调类型,任意的程序元素都必须显示指明