You Are Browsing ‘CBSE Class 12’ Category

Use of relational and logical operators in C++

In this lesson, we will learn about the various relational and logical operators in c++ and how they are used in forming expressions. One thing common to both these operators is that they evaluate to either a true or a false value. A true value is denoted by 1 and a false value is denoted by 0 in C++. 1. Relational Operators Let’s begin with relational operators. They are used to determine the relation...

Precedence of operators in C++ and expression evaluation

So far we have gone through the following operators in C++: Arithmetic Operators Increment and Decrement Operators Relational Operators Logical Operators Conditional Operator Assignment Operators Now let’s first understand what is meant by an expression. An expression is a sequence consisting of variables, constants and operators which specify a computation. That is, an expression can be evaluated to...

Meaning of implicit and explicit type conversion in C++

This lesson focuses on expressions consisting of mixed data types. The C++ compiler has a way to deal with expressions that contains variables or constants which have different data types. So if we have two different types of variables/constants in an expression, they can be converted to one single type (either by the compiler or explicitly by the programmer). This process is known as type conversion in C++. For...

What is the use of Conditional Operator in C++?

There is  a special operator called  conditional operator in  C++ programming language, denoted by ?: symbol. It is way different from the other operators in C++ programming language and provides a convenient way to take an action depending on the truth or falsity of a condition. Lets see how this operator works. First thing we need to know is that condition operator is a ternary operator. This means it takes...

How to use Increment (++) and Decrement (- -) Operators in C++ ?

Previously we had seen the various arithmetic operators in C++. Now let us have a look at two new operators called the increment (++) and decrement (- -) operators. Both these operators are unary operators. That means they work only on one operand. They can be used in two ways : 1. Prefix form 2. Postfix form Let us see each of these operators in both the forms stated above. 1. INCREMENT OPERATOR (++) The increment...

Various Data Type Modifiers in C++ : signed, unsigned, long, short

Now that we know the various data types used in C++ language, let us see how we can modify these data types to provide more versatility to our code. We have the following four data type modifiers in C++ : signed unsigned long short First let us discuss some imporant points about these modifiers. If we use ‘signed’ before a variable declaration, it means that the variable can hold both positive...

What are the Various Arithmetic Operators used in C++ ?

C++ programming language provides us with various types of operators for performing different tasks. One such class of operators is arithmetic operators. These are used for performing arithmetic calculations in a program. Following is a list of the C++ arithmetic operators: Addition operator:  ‘ + ‘ Subtraction operator:  ‘ – ‘ Multiplication Operator: ‘ * ‘ Division...

How to fix the value of a variable using const keyword in C++

A variable is an entity whose value can vary in a program. But sometimes, we need to fix the value of a variable for some purpose. For example, to calculate the area of a circle, we can store the value of PI which  is 3.14 in a variable. However we need to make sure that this value is not altered in the program otherwise we may get wrong results. So to fix the value of a variable, we use the keyword const before...

What are Various Types of Constants in C++ and their Use

We had given an introduction to constants when we had talked about the different types of tokens in C++. Now let us study constants in detail and see how they are used in C++ programs. First let us recall what constants are. DEFINITION : They are data items that do not change during a program. They are also called literals. So both the terms constants and literals are used interchangeably. TYPES OF CONSTANTS/LITERALS...

How to Declare and Initialize Variables in C++ – Tutorial for Beginners

In the previous post, we had seen what are the various built-in data types in C++. We are now ready to use them to create variables in our programs. First let us see what variables actually are and how they work. Definition : Variables are symbolic names given to memory locations that store various values. In other words, when we declare a variable and assign it any value, that value gets stored in memory at...