#include "stdafx.h"
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cmath>
using namespace std;
void fun(int x,int *y){
int a=4 ;
*y=x+a;
x=*y;
}
void main(void){
int a=2,b=3,*c=&b;
fun(a,c);
cout<<a<<endl;
cout<<b<<endl;
cout<<*c<<endl;
system("pause");
}
#include "stdafx.h"
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cmath>
using namespace std;
union st{
int a[2];
int b[2];
int c;
};
int main(){
union st y;
y.a[0]=10;
y.b[1]=20;
y.c=30;
cout<<y.a[0]<<endl;
cout<<y.a[1]<<endl;
system("pause");
return 0;
}
30 ,20
#include "stdafx.h"
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cmath>
using namespace std;
union out{
int a [2];
struct{
int b;
int c;
}in;
int d;
};
int main(){
union out e;
e.in.b=1;
e.in.c=2;
e.d=3;
for(int i=0;i<2;i++){
cout<<e.a[i]<<endl;
}
system("pause");
return 0;
}
3,2
#include "stdafx.h"
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cmath>
using namespace std;
int a=1;
int sub(int c,int d){
static int m=2,n=5;
cout<<m<<'\t'<<n<<'\t'<<endl;
a=++a;
c=m++;
d=n++;
return c+d;
}
int main(){
int m=1,n=2,f;
f=sub(m,n);
cout<<a<<'\t'<<f<<endl;
f=sub(m,n);
cout<<a<<'\t'<<f<<endl;
system("pause");
return 0;
}
2 5
2 7
3 6
3 9
#include "stdafx.h"
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cmath>
using namespace std;
void test1(int *a1){
a1=new int(5);
cout<<"*a1="<<*a1<<endl;
}
void test2(int * &a2){
a2=new int(5);
cout<<"*a2="<<*a2<<endl;
}
int main(){
int *p=new int(1);
test1(p);
cout<<"test1:*p1="<<*p<<endl;
test2(p);
cout<<"test2:*p2="<<*p<<endl;
system("pause");
return 0;
}
*a1= 5
test1: *p1= 1
*a2= 5
test2: *p2= 5
test1: *p1= 1
*a2= 5
test2: *p2= 5
#include "stdafx.h"
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cmath>
using namespace std;
class T{
public:
T(int x){a=x;b+=x;}
static void display(T c){
cout<<"a="<<c.a<<'\t'<<"b="<<c.b<<endl;
}
private:
int a;
static int b;
};
int T::b=5;
int main(){
T A(3),B(5);
T::display(A);
T::display(B);
system("pause");
return 0;
}
a=3 b=13
a=5 b=13
a=5 b=13
#include "stdafx.h"
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cmath>
using namespace std;
class Base1{
public:
Base1(int i){
cout<<"调用基类Base1的构造函数:"<<i<<endl;
}
};
class Base2{
public:
Base2(int j){
cout<<"调用基类Base2的构造函数:"<<j<<endl;
}
};
class A:public Base2,public Base1{
public:
A(int a,int b,int c,int d):Base2(b),Base1(c),b2(a),b1(d){
cout<<"调用派生类A的构造函数:"<<a+b+c+d<<endl;
}
private:
Base1 b1;
Base2 b2;
};
void main(){
A obj( 1, 2, 3, 4 );
system("pause");
}
调用基类BASE2的构造函数:2
调用基类BASE1的构造函数:3
调用基类BASE1的构造函数:4
调用基类BASE2构造函数:1
调用派生类A的构造函数:10
调用基类BASE1的构造函数:3
调用基类BASE1的构造函数:4
调用基类BASE2构造函数:1
调用派生类A的构造函数:10