Fundamentals of C Plus Plus (C++)

Unary Operators in C++

C++ includes a class of operators that act upon a single operand to produce a new value. Such operators are known as unary operators. Unary operators usually precede their single operands, through some unary operators are written after their operands. Perhaps the most common unary operation is unary minus, where a numerical constant, variable or expression is preceded by a minus sign. Note that the unary operation is distinctly different from the arithmetic operator which denotes subtraction (-) as the subtraction operator requires two operands. Example: -743 -0x7fff -0.2 -5E-8 -root1 -(x + y) -3 * (x + y)

Arithmetic Operators in C++

There are five arithmetic operators in C++. They are: Operator Purpose + addition – subtraction * multiplication / division % remainder after integer division The % operator is also sometimes referred to as the modulus operator. Example of the use of Arithmetic Operators: Suppose that the x and y are integer variables whose values are 10 and 3 respectively. Several arithmetic expressions involving these variables are shown below, together with their resulting values: Expression Values x + y 13 x – y 7 x * y 30 x / y 3 x % y 1 In the above mentioned example, notice the truncated quotient resulting from the division operation (x / y), since both operands represent integer quantities. Also, notice the integer remainder resulting from the use of the modulus operator in the last expression (x % y). Precedence of Arithmetic Operators: Among the arithmetic operators, *, / and %...

Operators and Expressions in C++

An operator, in general, is a symbol that operates on a certain data-type. For example, the operator + is the addition operator. It can operate on integer, character and real (float and double) numbers. On the other hand, an expression is a combination of variables, constants and operators written according to the syntax of the language. Types of Operators: Arithmetic operators Unary operators Increment and Decrement operators Relational operators Logical operators Assignment operators Conditional operators

Variables and Declarations in C++

Variables in C Plus Plus (C++): A variable can be defined as “a quantity that varies during program execution”. A variable is a symbol that represents a storage location in the computer’s memory. The information that is stored in that location is called the value of the variable. One common way for a variable to obtain a value is by an assignment. This has the syntax: variable = expression First, the expression is evaluated and then the resulting value is assigned to the variable. The equal sign “=” is the assignment operator in C++. Declarations in C++: A declaration associates a group of variables with a specific data-type. All variables must be declared before they can appear in executable statements. A declaration consists of a data-type, followed by one or more variable names, ending with a semicolon. Example: int a, b, c; float root1, root2; char flag; Here,a, b and c are...

Data Types in C++

Data types supported by C++ can be broadly divided into six heads as stated follows: int data-type char data-type float data-type double data-type bool (boolean) data-type enum (enumeration) data-type 1) int data-type: int data-type represents the whole number (i.e., integer) quantities. Integers are required not to contain a decimal point or an exponent. int data-type can also be further sub-divided into two broad categories, viz, short int and long int signed int and unsigned int short int and long int The qualifier short, when placed in front of the int declaration, tells the C++ system that the particular variable being declared will be used to store fairly small integer values. On the other hand, the qualifier long, when placed in front of the int declaration, tells the C++ system that the particular variable being declared will be used to store fairly large integer values. signed int and unsigned int In case...

Identifiers and Keywords in C++

In a C++ program (i.e., a program written in C++ language), every word is either classified as an identifier or a keyword. Identifiers, as the name suggests, are used to identify or name various program elements such as variables, constants, functions etc. On the other hand, Keywords are a kind of reserved word which have standard, predefined meanings in C++. Now, let us discuss these concepts in details: Identifiers: As stated before, identifiers are names that are given to various program elements such as variables, constants, functions, arrays etc. There are certain rules regarding identifier names in C++, as stated below: Identifiers must consist of letters and digits, in any order, except that the first character must be a letter Both upper-case and lower-case letters are permitted, though common usage favours the use of lower-case letters for most types of identifiers. Upper-case and lower-case letters are not interchangeable i.e., an upper-case...