本文一些代码的形式演示c++语言的特性,关于环境的搭建可以参考 设置 Windows 下的GCC开发环境
- 代码: s1.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| #include<bits/stdc++.h> using namespace std;
struct person { char name[15]; char sex; int age; };
int main( ) { struct person p1 = {"Tom", 'm', 24}, p2, *p = &p2;
strcpy(p2.name, "Jack");
p2.sex = 'f'; p2.age = p1.age+3;
cout<<p1.name<<p1.sex<<p1.age<<endl; cout<<p->name<<p->sex<<p->age<<endl; }
|
找出一下代码中的错误:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| #include<bits/stdc++.h> using namespace std;
int main( ) { struct abc { char name[10]; float score; } s1,s2;
s1->name="tom "; s1.name="tom"; strcpy(name, "tom") ; strcpy(test.name, "tom"); score=90; s2=s1;
cout<<s1.name<<s1.score<<endl; cout<<s2->name<<s2->scoreendl; }
|