Data Handling and Expressions :

Data Type Modifiers :

You can apply the modifiers signed, unsigned, short and long to character and integer base types. However you may also apply long to double.

Integer Type Modifiers :

TypeApproximate Size
short

unsigned

signed short
2byte

2bytes

2bytes
int

unsigned int

signed int
2byte

2bytes

2bytes
long

unsigned long

signed long
4byte

4bytes

4bytes

Character Type Modifiers :

TypeApproximate Size
char

unsigned char

signed char
1byte

1bytes

1bytes

Floating Type Modifiers :

TypeApproximate Size
float

double

long double
4byte

8bytes

10bytes

Operators and Expressions :

C language Operators and Expressions - C ++ Operators - C++ is very rich in built-in operators. In fact, C++ places more significance on operators than most other computer languages do.

Arithmetic Operators :

It provides operators for five basic arithmetic calculation : addition, subtraction, multiplication, division and remainder which are +, -, *, / and % respectively.

OperatorNameExampleResult
+addition6 + 511
-subtraction6 - 51
*multiplication6 * 530
/division60 / 512
%addition60 % 50

Increment and Decrement Operators :

C++ includes two useful operators these are the increment and decrement operators, ++ and --. The C++ name itself is influenced by the increment operator ++. The operator ++ add 1 to its operand, and -- subtract 1.

a = 15;
a++ or ++a will produce the result a = 16.

a = 15;
a-- or --a will produce the result a = 14.

Note : That a++ and a-- are referring the post-fix increment and decrement operation, and ++a and --a are referring the prefix increment and decrement operation.

Relation Operators :

Relation refers to the relationships that values (or operands) can have with one another.

OperatorNameExampleResult
==comparison (equality)6 == 5false
<less than6 < 5false
<=less than or equal to6 <= 5false
>greater than6 > 5true
>=greater than or equal to6 >= 5true
!=not equal to6 != 5true

Logical Operators :

The previous section discussed about relational operators that establish relationships among the values. This selection talks about logical operators that refer to the ways these relationships (among values) can be connected.

OperatorNameExampleResult
&&and(6 <= 6) && (5 < 3)false
||Or(6 <= 6) || (5 < 3)true
!Or!(6 <= 6)false

Conditional Operators :

C++ offers a conditional operator (?:) that stores a value depending upon a condition, this operator also called Ternary operator. The general condition follows :

expression1? expression2 : expression3
result=marks>=50?'P':'F';

The identifier result will have value 'P' if the test expression marks >= 50 evaluates to true(1) otherwise result will have 'F'.

Some Other Operators :

There are a lot many other operators in C++, other than the ones discussed here. But in this section, we are discussing two of them that are of relevant use to you right now. two operators are : sizof and comma operator.

The sizeof Operator :

float fl;
cout<<"The sizeof float variable fl is"<<sizeof fl;
cout<<"The sizeof integers is"<<sizeof (int);


Note : Assuming that integer-size is 2 bytes and float-size is 8 bytes.


The Comma Operator :

b = ( a = 3, a + 1 );

First assigns a value 3 and then assigns b the value a + 1.

Note : The parentheses are necessary because the comma operator has a lower precedence than the assignment operator.


Next Update

Loading...

We adding new programming language tutorials very soon.

We make a Collaboration with HackIsOn YouTube Channel So, Please Subscribe Their Channel and keep supporting