c++ 基础之 namespace_quote

#include <stdlib.h>
#include <iostream>
using namespace std;
//标准命名空间(包含很多标准的定义)
//standard
/*using namespace std;
//命名空间类似于java中的包(归类)


//自定义命名空间
namespace NSP_A{
int a = 9;
}
namespace NSP_B{
int a = 18;
//命名空间嵌套
namespace NSP_C{
int a = 22;
}
}
void main(){


printf("this is c in c plus\n");
//std:cout << "this is c plus_plus" << std:: endl;
     cout << "this is c plus_plus" << endl;


cout << NSP_A::a<< endl;
cout << NSP_B::a << endl;
cout << NSP_B::NSP_C::a<< endl;
getchar();
}*/
/* #define PI 3.14
//类 圆
class Mcircle{
//属性(共用访问权限修饰符)
private:
double r;
double s;
    public : 
void setR(double r){
this->r = r;
}


double getS(){
return PI*r*r;
}
};


void main(){
Mcircle c1;
c1.setR(4);
std::cout << "原型面积:" << c1.getS() << std::endl;
getchar();
}
*/
/*结构体
struct MyTeacher{


public :
char name[20];
int age;


public :
void say(){
cout << this->age << "岁" << endl;
}




};


void main(){
MyTeacher t;
t.age = 18;
t.say();
getchar();
}*/




/*
void main(){
//布尔类型
bool isSingle = true;
if (isSingle){
cout << "单身" << endl;
}
else{
cout << "有对象" << endl;

}
//三目运算符可以作为左值
int a = 10; int b = 20;
((a > b) ? a : b) = 99;
cout << "b="<<b<< endl;


getchar();



}


*/
/*
//引用
void main(){
//变量名-门牌号(内存空间0x-00001的别名)
int a = 10;
//b就是这个内存空间的别名  &在c++中代表引用
int &b = a;
int* c = &a;
b = 55;  //修改了地址上的值  b = 55  *c =55;
cout << b << endl;
cout << *c << endl;
getchar();


}
*/


void swap_p(int* a,int* b){
int c = 0;
c = *a ;
*a =*b;
*b = c;
}


//引用的用处
void  swap_u(int &a,int &b){
int c = 0;
c = a;
a = b;
b = c;
}


void main(){
int x = 10;
int y = 20;
printf("%d,%d\n",x,y);
int* xp = &x;
int* yp = &y;
swap_p(xp,yp);
printf("%d,%d\n", x, y);
swap_u(x, y);
printf("%d,%d\n", x, y);
getchar();
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值