B.Tech Students: Apply for Live Programming Internship C, C++, Java, Python ,Web page Designing, PHP C++ Operators | Login Technologies

C++ Operators

C++ operators are symbols used to perform operations on variables and values like addition, comparison, logic, etc.

C++ ऑपरेटर symbols होते हैं जो variables और values पर operations (जैसे जोड़, तुलना, लॉजिक) करने में यूज़ होते हैं।

Example 1: Addition (+)

#include <iostream>

int main() {
    int a = 5, b = 3;
std::cout << "Sum = " << a + b;
    return 0;
}

Explanation: Adds two numbers.

व्याख्या: दो numbers को जोड़ता है।

Output: Sum = 8


Example 2: Subtraction (-)

#include <iostream>

int main() {
    int a = 5, b = 3;
std::cout << "Difference = " << a - b;
    return 0;
}

Explanation: Subtracts second from first.

व्याख्या: पहले में से दूसरे को घटाता है।

Output: Difference = 2


Example 3: Multiplication (*)

#include <iostream>

int main() {
    int a = 5, b = 3;
std::cout << "Product = " << a * b;
    return 0;
}

Explanation: Multiplies two numbers.

व्याख्या: दो numbers को multiply करता है।

Output: Product = 15


Example 4: Division (/)

#include <iostream>

int main() {
    int a = 10, b = 2;
std::cout << "Quotient = " << a / b;
    return 0;
}

Explanation: Divides first by second.

व्याख्या: पहले number को दूसरे से divide करता है।

Output: Quotient = 5


Example 5: Modulus (%)

#include <iostream>

int main() {
    int a = 10, b = 3;
std::cout << "Remainder = " << a % b;
    return 0;
}

Explanation: Gives remainder.

व्याख्या: शेषफल देता है।

Output: Remainder = 1


Example 6: Equal To (==)

#include <iostream>

int main() {
    int a = 4, b = 4;
std::cout << "Equal: " << (a == b);
    return 0;
}

Explanation: Checks if both are equal.

व्याख्या: दोनों बराबर हैं या नहीं, चेक करता है।

Output: Equal: 1


Example 7: Not Equal (!=)

#include <iostream>

int main() {
    int a = 5, b = 3;
std::cout << "Not Equal: " << (a != b);
    return 0;
}

Explanation: Checks if not equal.

व्याख्या: बराबर नहीं हैं या नहीं, चेक करता है।

Output: Not Equal: 1


Example 8: Logical AND (&&)

#include <iostream>

int main() {
    int a = 1, b = 0;
std::cout << "AND: " << (a && b);
    return 0;
}

Explanation: True if both true.

व्याख्या: दोनों true हों तो true देता है।

Output: AND: 0


Example 9: Logical OR (||)

#include <iostream>

int main() {
    int a = 1, b = 0;
std::cout << "OR: " << (a || b);
    return 0;
}

Explanation: True if at least one true.

व्याख्या: कम से कम एक true हो तो true देता है।

Output: OR: 1