C++ Programming Language

  • Home
  • C++ Programming Language
Shape Image One

C++ PROGRAMMING LANGUAGE

advanced divider

C++ PROGRAMMING LANGUAGE:

C++ is a powerful general-purpose programming language. It was created by Bjarne Stroustrup in 1979 at Bell Laboratories. It is used to develop operating systems, browsers, games, and other applications. C++ supports mainly support programming like object oriented. C++ is a flexible language aims to make writing programs easier and more pleasant for the individual programmer.

RESERVED WORDS IN C++:

Reserved words are keywords that have standard predefined meanings in C++ language. These keywords can only be used for their intended purpose; they cannot be used as programmer defined identifiers.
The following list the keywords or reserved words of the C++ language:

C++ Keywords
Keyword Keyword Keyword Keyword
asm else new this
auto enum operator throw
bool explicit private true
break export protected try
case extern public typedef
catch false register typed
char float reinterpret_cast TypeName
class for return union
const friend short unsigned
const_cast goto signed using
continue if sizeof virtual
default inline static void
delete int static_cast volatile
do long struct wchar_t
double mutable switch while
dynamic_cast namespace template and
or not requires nullptr

C++ DATA TYPES:

Data values passed in a program may be of different types. Each of these data types are represented differently within the computer’s memory and have different memory requirements. These data types can be augmented by the use of data type qualifiers / modifiers.

The data types supported in C++ are described below:

Data Types and Ranges
Data Type Keyword Size Range
Boolean bool 1 Byte 0 (false), 1 (true)
Character char 1 Byte -127 to 127 OR 0 to 255
Integer int 4 Bytes -2,147,483,648 to 2,147,483,647
Floating Point float 4 Bytes 1.5 x 10^-45 to 3.4 x 10^38
Double Floating Point double 8 Bytes 5.0 x 10^-345 to 1.7 x 10^308

CONSTANT:

A constant is an identifier whose value remains unchanged throughout the program. Constants are used in two ways, they are:

⦁ Literal Constants
⦁ Defined Constants

LITERAL CONSTANT:

Literal constants are data used for representing fixed values. They can be used directly in the code.
Example: 1, 2.5, ‘c’, “good” etc.

DEFINED OR SYMBOLIC CONSTANT:

In C++, we can create symbolic constant whose value remains unchanged but used as a variable. A symbolic constant can be created using the #define preprocessor directive or const keyword.

Example:

const int LIGHT_SPEED=299792458;
#define LIGHT SPEED 299792458

VARIABLE:

A variable is nothing but a name given to a storage area that our programs can manipulate. Its value can change during program execution. Each variable in C++ has a specific data type, which determines the size and layout of the variable’s memory.

RULES FOR NAMING VARIABLE:

• A variable name contains alphabets, numbers, and the underscore.
• A variable name must start with a letter or an underscore.
• Variable names are case sensitive. (Sum and sum are different)
• A variable name cannot be a keyword.
• A variable name cannot be longer than 32 characters.

DECLARATION (CREATING) VARIABLES:

Variable declaration is a process in which we create storage space for variable in memory. A variable declaration consists of data type and name of the variable written as follow: data_type variable_name;
int sum;

INITIALIZATION:

Assign initial value to a variable is known as variable initialization. It can be initialized during declaration or separately. The equal sign is used to assign value written as follows: data_type variable_name = value;
int sum = 3;

STRINGS IN C++:

Variables that can store alphanumeric value that consist of multiple characters are called strings. In C++, strings are used by one-dimensional array of characters, which is terminated by a null character \0.

Quiz

advanced divider