C++ 数组的各类性质和用法
#include<iostream>
using namespace std;
void addarr(int *k,int len);
//文中形如sizeof(x)/sizeof(x[0]) 是用数组占用空间大小除以成员的大小,即得数组长度
//三种不同的数组声明方式
int x[5]={1,2,3,4,5};
int y[]={2,4,6,8,10};
数据结构
#include<iostream>
using namespace std;
struct books{
char name[10];
int num;
float price;
}book;
int main()
{
book.num=1;
book.price=2.5;
char x[10]="Hello",n;
for(n=0;n<1
C和C++中的字符串
/*C风格字符串的声明和使用
#include<cstdio.h>
int main()
{
char x[]={'H','e','l','l','o',' ','C','+','+','\0'};
//等效于 char x[]="Hello
Break和Continue的区别
#include<iostream>
using namespace std;
int main()
{
int x=0;
for(x=0;x<10;x++)
{
if(x==3)
break;
else
cout << x;
}
cout << endl;
for(x=0;x<10;x++)
{
变量作用域
#include<iostream>
void print();
int main()
{
char a=0;
for(a=0;a<20;a++)
print();
return 0;
}
void print()
{
static int x=0;//静态变量声明,其值会一直保留
x++;
std::cout<<x<
函数声明和使用
#include<iostream>
using namespace std;
int sum(int a,int b);//函数声明
int main()
{
cout << sum(1,2);//函数调用
return 0;
}
int sum(int a,int b)//函数主体
{
r
数据类型及其占用空间
#include<iostream>
using namespace std;
int main()
{
cout << "The size of int is " <<sizeof(int) <<endl;
cout << "The size&
C++入门 输出Hello World
#include <iostream>using namespace std;int main(){
cout << "Hello, world!" << endl; return 0;}它等效于#include <iostream
C++的继承和派生
#include <iostream>
using namespace std;
class fenshu
{
public:
int xuehao;
int yuwen;
};
class wz_fenshu:public fenshu
{
public:
int shuxue;
&