int a=0;
#include <iostream>
using namespace std;
void main()
{
int a = 11;
cout << &a << endl;
}
*和&运算符的用法:
void main()
{
int a=11;
int * b=&a;
int c=*b;
}
void main()
{
int a = 10;
int* b = &a;
cout << sizeof(b) << endl;
}
void main()
{
int* c = NULL;
cout << *c << endl;
}
void main()
{
int* d=(int *)0x1199;
cout << *d << endl;
}
void main()
{
int a = 10;
int* b = &a;
const int* e = &a;
int aa = 100;
e = &aa;
cout << *e << endl;
int * const ee = &a;
*ee = 1000;
const int* const eee = &a;
}
void main()
{
int arr[] = { 1,3,2 };
cout << arr[0] << endl;
cout << *arr << endl;
for (int i = 0; i < 3; i++)
{
cout << *(arr+i) << endl;
}
}
void Swap(int a,int b)
{
int temp = a;
a = b;
b = temp;
cout << "Swap a" << &a << endl;
cout << "Swap b" << &b << endl;
}
void main()
{
int a = 11;
int b = 22;
Swap(a,b);
cout << " a" << &a << endl;
cout << " b" << &b << endl;
}
void Swap(int* a,int* b)
{
int * temp = *a;
*a = *b;
*b = *temp;
cout << "Swap a" << a << endl;
cout << "Swap b" << b << endl;
}
void main()
{
int a = 11;
int b = 22;
Swap(&a,&b);
cout << " a " << a << endl;
cout << " b " << b << endl;
}
void Swap(int* a, int* b)
{
cout << "Swap a " << a << endl;
cout << "Swap b " << b << endl;
cout << "Swap a " << *a << endl;
cout << "Swap b " << *b << endl;
cout << "Swap &a " << &a << endl;
cout << "Swap &b " << &b << endl;
int * temp = a;
a = b;
b = temp;
cout << "Swap a " << a << endl;
cout << "Swap b " << b << endl;
cout << "Swap a " << *a << endl;
cout << "Swap b " << *b << endl;
}
void main()
{
int a = 11;
int b = 22;
Swap(&a,&b);
cout << " a " << &a << endl;
cout << " b " << &b << endl;
cout << " a " << a << endl;
cout << " b " << b << endl;
}
void Swap1(int & a, int &b)
{
cout << " &a " << &a << endl;
cout << " &b " << &b << endl;
cout << " a " << a << endl;
cout << " b " << b << endl;
int temp = a;
a = b;
b = temp;
}
void main()
{
int a = 11;
int b = 22;
Swap1(a,b);
cout << " &a " << &a << endl;
cout << " &b " << &b << endl;
cout << " a " << a << endl;
cout << " b " << b << endl;
}
this关键字
class Person
{
public:
Person(int age,int c)
{
this->age = age;
this->c = c;
}
void Show()
{
cout<<this<<endl;
cout<<&this->age<<endl;
cout << &this->c << endl;
}
Person Return()
{
return *this;
}
Person& Return1()
{
return *this;
}
private :
int age;
int c;
};
void main()
{
Person p(1,2);
p.Show();
p.Return().Show();
p.Return1().Show();
}