运算符

按位运算符

<< >> ~ & | ^ 一共6个

移位运算符

value<<shift;
13<<3; 13*2^3;

逻辑按位运算符

  1. !非运算符:将true或者非零值转为false,将false值转为true
  2. ~位非(取反)运算符。将其值的二进制0-》1 1-》0;
    usigned char x = 3; 0000 0011 ->1111 1100 252
  3. 按位运算符(or)| , 两个数有1就为1.
    在这里插入图片描述
  4. 按位运算符(xor)^ ,相同为0,不同为1
    在这里插入图片描述
  5. 按位运算符(AND)& ,都为1才1
    在这里插入图片描述

按位运算的替代表示

在这里插入图片描述

常用的按位运算技术

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

成员解除引用运算符

C++允许定义指向类成员的指针,对这种指针进行声明或解除引用时,需要用一种特殊的语法。
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

// class.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//
#include <iostream>
#include<string>
using namespace std;
class Example {
private:
	int feet;
	int inches;
public:
	Example() { feet = 0; inches = 0; };
	Example(int ft) { feet = ft; inches = 12 * feet; };
	~Example() {};
	void Show_in()const { cout <<"inches :"<< inches << endl; };
	void Show_ft()const { cout << "feet :" << feet << endl; };
	void use_ptr()const;
};
void Example::use_ptr()const
{
	Example yard(3);
	int Example::* pt;
	pt = &Example::inches;
	cout << "set pt to &Example::inches:\n";
	cout << "this->*pt :" << this->*pt << endl;
	cout << "yard.*pt :" << yard.*pt << endl;
	void (Example:: * pf)()const;
	pf = &Example::Show_in;
	cout << "set pf to &Example::Show_in\n ";
	cout << "(this->*pf):";
	(this->*pf)();
	cout << "(yard.*pf)();:";
	(yard.*pf)();
}
int main()
{
	Example car(15);
	Example van(20);
	Example garage;
	cout << "use car :\n";
	car.use_ptr();
	cout << "\n van use car :\n";
	van.use_ptr();
}

alignof(c++11)

在这里插入图片描述

// class.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//
#include <iostream>
#include<string>
using namespace std;
struct  things1
{
	char ch;
	int a;
	double x;
};
struct  things2
{
	int a;
	double x;
	char ch;
};

int main()
{
	things1 th1;
	things2 th2;
	cout << "char alignment :" << alignof(char) <<endl;  //1
	cout << "int alignment :" << alignof(int) << endl;//4
	cout << "double alignment :" << alignof(double) << endl;//8
	cout << "things1 alignment :" << alignof(things1) << endl;//8
	cout << "things2 alignment :" << alignof(things2) << endl;//8
	cout << "sizeof things1 :" << sizeof(things1) << endl;//16
	cout << "sizeof things2 :" << sizeof(things2) << endl;//24
}

在这里插入图片描述

noexcept(c++11)

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值