Operators based on operand count – Computer Sir Ki Class


Lost your password?

Don't have an account ?
Register (It's FREE) ×


Code Learning #CPP#1728 siteicon   siteicon   siteicon  

Operators based on operand count

Binary, unary and ternary operator classification is based on number of operands.

Learning Objectives

  • Understanding operators classification on the basis of number of operands.

Source Code

TC++ #1728


Source Code

Alternate (?) :   Related (?) :

Run Output


Code Understanding

int a=10;
This will initialise the integer variable a with a value of 10.

cout<<a+a<<endl; cout<<a-a<<endl; cout<<a*a<<endl; cout<<a/a<<endl;
Will produce output 20, 0, 100 and 1 as per the given arithmetic operator.

cout<<a++<<endl; cout<<a<<endl;
This will post increment the value of a, which means that the effect of increment will be visible in next instruction. So the output of 10 and 11 will be produced by these two instructions.

This will pre-decrement the value of a. The value in previous instruction is 11 so this will now print 10 again.

int b=(a)?++a:–a;
This is the ternary operator which is a combination of three operands.  (a) means the condition check operand. Here we are checking if a is true. Since a is non-zero value so it is taken as true and hence the first operand before : character is activated. If condition is false then second value after : character is activated. So b will contain ++a which is 11. Here three operands are (Condition check operand) ? (Value when true operand) : (value when false operand)

The value of b which is 11 shall be printed.

Suggested Filename(s): operators-but.cpp,operandcount.cpp


CSKC| Created: 15-Dec-2017 | Updated: 4-Jan-2019|

Introductory Sessions Beginning to Program Tokens Keyword and Identifiers Data Types Variables and Constants Operators Simple User Input Building Expressions and Formulas Simple Real World Problems Simple If and If Else Multiple-Nested-Ladder of If Else Switch case selection Simple Loops Tricks in Loops - break continue scope Loop Applications - Handling numerals Series printing loops Nested Loops Pattern printing loops Number Varieties and Crunches String Handling (Null Terminated) Strings - string class type Functions (Built-in) Functions - user defined Functions Reference Passing/Returning Arrays Concepts and 1-D Arrays Array Data Management Two dimensional arrays and Matrices Structures Basics Structures passing/returning 2D Array Memory Addressing Display Using IO Manipulation Display Using C Formatting Tricks User Defined Data Types Enumerated Types Preprocessor Directives And Macros Exception Handling Programming Paradigms and OOPs Advantages Abstraction and Encapsulation Polymorphism Inheritance Function Overloading Concepts Function Overloading Varieties Function Overloading Special Cases Defining Classes Creating and Using Class Objects Class Members Accessibility Class Function Types Inline Functions Constant Functions Nesting of Functions Class Members Scope Resolution Static Members in a Class Array of Objects Constructor Concepts Default Constructor Parameterized Constructor Copy Constructor Constructor Overloading Destructors Inheritance Fundamentals Public Derivations Private and Protected Derivations Multiple Inheritance Multi-Level Inheritance Class Nesting Data File Concepts Handling Text Files Handling Binary Files Pointer Concepts Pointer and Arrays Pointers and Functions Object Pointers This Pointer Linked Lists Stacks Queues