Getting Started With C++
C++ is a high-level programming language developed by Bjarne Stroustrup at AT&T Bell Laboratories in the early 1980s. Since C language was lacking in simulations and a bit of security as C language does not support Class and Objects feature which provide security to the programming languages. C++ is the update of C language so it is named as C++ by Rick Mascitti where ++ represent the increment operator in C language.
Frequently used terms:-
Header File – It is a file with extension .h which is used to link the program with predefined functions.
Variables – This word is used to represent a combination of alphabets and numbers to perform all operations.
Data Types- User defines variable along with their data type which represents the type of variable.
Functions- A segment of code defined to perform any operation any number of times.
Loops- Loops are the segment of code which automatically runs multiple numbers of times depending upon condition.
Conditional Statement- This segment of code executes only when the condition is satisfied.
Operators- Operators are used where some computation is required either mathematical computation or Boolean etc.
Keywords- this is the word which triggers some special meanings.
- Header Files:- Header Files contains the definition of Functions and Variables which can be imported and used by the user.
Commonly used header files:–
Iostream:- this header file is used to import the definition of standard input and output functions i.e., cin and cout.
Conio.h:– commonly used to hold the screen and clear screen functions, i.e., clrscr() and getch() functions.
Stdio.h:– this header file holds the definition of macros and types required for standard I/O package i.e., scanf & printf.
String.h:- This header file is used for string manipulation i.e., strcmp, strcpy etc.
Math.h:- This header holds the definition of commonly used maths functions like sqrt, sinh etc.
Stdlib:- this header file is used for standard conversion, searching sorting etc.
- Variables:- Variables are used to provide named storage to all our inputs on which we need to perform operations.
- Data Types of variables:–
Int- Integer type of variable which is used to hold integer values. It occupies 4 bytes of memory and ranges from -32,767 to 32,767.
Char- used to store a single character value. It occupies 1 byte of memory. It ranges from -127 to 127.
Float- it is used to store decimal type of variables. It occupies 4 byte of memory. It ranges from +/- 3.4e +/- 38 (~7 digits).
Double- it is used to represent a long range of integer value. It occupies 8 bytes of memory and ranges from +/- 1.7e +/- 308 (~15 digits).
- Functions:- Functions are of two types-
- Predefined Functions
- User defined functions
- Predefined Functions:- This type of functions are predefined and loaded into header files which can be imported and used by the user.
Examples:- sqrt(in math.h), strcpy(in string.h).
- User-defined Functions:- User can create his own segment of code as a function where user-defined operation will be performed and can be called multiple times.
- Loops:- Types of loops are:-
- For loop.
- Do-while loop.
- While loop.
These loops will be explained in further topics.
- Conditional statements:-
Types of conditional statements
- Nested if
- Nested if-else
This topic will be further explained in a separate section.
Types of operators:-
- Arithmetic operators:- +,-,=,*,/,% etc.
- Increment/Decrement operator:- ++/–
- Relational Operators:- <,>,<=(less than equals),>=(greater than equals),==(Equals),!=(Not equals).
- Logical operator:- &&(logical and),||(logical OR)
- Keywords:- Commonly used keywords are-
If, else, int, char, float, double, long, return, void, while etc.
By Bhoj Kumar