Los operadores son la base de cualquier lenguaje de programación. Podemos definir operadores como símbolos que nos ayudan a realizar cálculos matemáticos y lógicos específicos sobre operandos. En otras palabras, podemos decir que un operador opera los operandos. Por ejemplo, ‘+’ es un operador que se usa para sumar, como se muestra a continuación:
c = a + b;
Aquí, ‘+’ es el operador conocido como operador de suma y ‘a’ y ‘b’ son operandos. El operador de suma le dice al compilador que agregue los dos operandos ‘a’ y ‘b’.
C++
// Operators in C++ #include<iostream> using namespace std; int main(){ int a=10, b=5; // Arithmetic operators cout<<"Following are the Arithmetic operators in C++"<<endl; cout<<"The value of a + b is "<<a+b<<endl; cout<<"The value of a - b is "<<a-b<<endl; cout<<"The value of a * b is "<<a*b<<endl; cout<<"The value of a / b is "<<a/b<<endl; cout<<"The value of a % b is "<<a%b<<endl; cout<<"The value of a++ is "<<a++<<endl; // First print (a) and then increment it by 1 cout<<"The value of a-- is "<<a--<<endl; // First print (a+1) and then decrease it by 1 cout<<"The value of ++a is "<<++a<<endl; // Increment (a) by (a+1) and then print cout<<"The value of --a is "<<--a<<endl; // Decrement (a+1) by (a) and then print cout<<endl; // Assignment Operators --> used to assign values to variables // int a =3, b=9; // char d='d'; // Comparison operators // Output of all these comparison operators will be (1) if it is true and (0) if it is false cout<<"Following are the comparison operators in C++"<<endl; cout<<"The value of a == b is "<<(a==b)<<endl; cout<<"The value of a != b is "<<(a!=b)<<endl; cout<<"The value of a >= b is "<<(a>=b)<<endl; cout<<"The value of a <= b is "<<(a<=b)<<endl; cout<<"The value of a > b is "<<(a>b)<<endl; cout<<"The value of a < b is "<<(a<b)<<endl; cout<<endl; // Logical operators cout<<"Following are the logical operators in C++"<<endl; cout<<"The value of this logical and operator ((a==b) && (a<b)) is:"<<((a==b) && (a<b))<<endl; cout<<"The value of this logical or operator ((a==b) || (a<b)) is:"<<((a==b) || (a<b))<<endl; cout<<"The value of this logical not operator (!(a==b)) is:"<<(!(a==b))<<endl; return 0; } // This code is contributed by Suruchi Kumari
Publicación traducida automáticamente
Artículo escrito por GeeksforGeeks-1 y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA