# C++ Programming Code Examples

## C++ > Beginners Lab Assignments Code Examples

### Assignment Operations in C++ programming language

/* Assignment Operations in C++ programming language
The operator "=" is an assignment operator in C++ and it assigns a value to the objects on the left. C++ provides capability to combine assignment operator with almost all the operation we have discussed above and forms a "Composite Assignment Operator". For example we can add a value to a variable as shown below */
int k = 9;
//normal way of adding value
k = k + 7;
//you can add value in a more compact way by combining two operators
//Composite assignment will be
k += 7; // this is equal to k = k + 7
Let X = 10 initially for the below examples
Composite Assignment Operator Example Is Equivalent to Output
+= X += 2 X = X + 2 12
-= X -= 2 X = X - 2 8
*= X *= 2 X = X * 2 20
/= X /= 2 X = X / 2 5
%= X %= 2 X = X % 2 0
<<= X <<= 2 X = X << 2 40
>>= X >>= 2 X = X >> 2 2
&= X &= 2 X = X & 2 2
^= X ^= 2 X = X ^ 2 8
|= X |= 2 X = X | 2 10

As the name already suggests, these operators help in assigning values to variables. These operators help us in allocating a particular value to the operands. The main simple assignment operator is '='. We have to be sure that both the left and right sides of the operator must have the same data type. We have different levels of operators. Assignment operators are used to assign the value, variable and function to another variable. Assignment operators in C are some of the C Programming Operator, which are useful to assign the values to the declared variables. Let's discuss the various types of the assignment operators such as =, +=, -=, /=, *= and %=. The following table lists the assignment operators supported by the C language:

The C++ comments are statements that are not executed by the compiler. The comments in C++ programming can be used to provide explanation of the code, variable, method or class. If we write comments on our code, it will be easier for us to understand the code in the future. Also, it will be easier for your fellow developers to understand the code. By the help of comments, you can hide the program code also. There are two types of comments in C++: • Single Line comment. • Multi Line comment

The bitwise operators are the operators used to perform the operations on the data at the bit-level. When we perform the bitwise operations, then it is also known as bit-level programming. It consists of two digits, either 0 or 1. It is mainly used in numerical computations to make the calculations faster. We have different types of bitwise operators in the C++ programming language. The following is the list of the bitwise operators: Bitwise AND operator is denoted by the single ampersand sign (&). Two integer operands are written on both sides of the (&) operator. If the corresponding bits of both the operands are 1, then the output of the bitwise AND operation is 1; otherwise, the output would be 0. This is one of the most commonly used logical bitwise operators. It is represented by a single ampersand sign (&). Two integer expressions are written on each side of the (&) operator.

Arithmetic Operator is used to performing mathematical operations such as addition, subtraction, multiplication, division, modulus, etc., on the given operands. For example: 6 + 3 = 9, 5 - 3 = 2, 3 * 4 = 12, etc. are the examples of arithmetic operators. Let's discuss the different types of Arithmetic Operators in the C programming. Plus Operator is a simple Plus (+) Operator used to add two given operands. We can use Plus Operator with different data types such as integer, float, long, double, enumerated and string type data to add the given operand. The minus operator is denoted by the minus (-) symbol. It is used to return the subtraction of the first number from the second number. The data type of the given number can be different types, such as int, float, double, long double, etc., in the programing language.

1:-) As we have seen that any class that has a pure virtual function is an abstract class. 2:-) We cannot create the "instance" of abstract class. For example: If I have written this line

The second power was described in terms of the area of a square, as in the above formula. It led to the use of the term square to mean raising to the "second power". Thus the area