c++ and operator code example

Example 1: how to write an or in c++

if (a == 0 || b == 0)
{
  //statement here, || was used as an or
}

Example 2: c++ .* operator

The .* operator is used to dereference pointers to class members.

Example 3: and c++

#include<iostream>
using namespace std;
int main(){
	int a;
	cin>>a;
	if(a >= 20 && a <= 30){
		cout<<"Il numero inserito è compreso tra 20 e 30";
	}
	else{
		cout<<"Il numero inserito non è compreso tra 20 e 30";
	}
}

Example 4: opperanf >> c++

packet >> rec1.getPosition().x >> rec1.getPosition().y;

Tags:

Cpp Example