Storage Classes in the C++ language.

C++ Programming Tutorial

Storage Classes in the C++ language.


This is a concept derived from the "C" language, in which it is decided which data is being stored and how it is being used. By using the Concept of Storage class.






Declarations and Definitions of Storage Classes.

When we give a name to a Variable or Function and decide its Data Type, this process is called Declaration. The declaration is information for Compiler. The compiler does not take any action on a Declaration.

To allocate space in memory for the Compiler Variable. We have tried to note the difference between these two at many places while explaining the functions.

void function(); // function declaration void function() // function definition { // statements }

Automatic Variables.

Variables that are declared within a block are useable, they are Automatic Variables.

void func() { int ivar; // automatic variables float fvar; }

Register Variables

Register Variable is a special type of Automatic Variable. When we want to declare a register class to a Variable, then we have to use register Keyword. That is, we can declare a Variable of Register Class.

register int Total;

External Variables

Variables that are declared outside a function or class are called Variables of External Storage Class. These are also called Global Variables.

Local Static Variables

A variable that is declared with static keyword is called static variable.

void function1() { int x=10;//local variable static int y=10;//static variable x=x+1; y=y+1; printf("%d,%d",x,y); }

If you call this function many times, local variable will print the same value for each function call e.g, 11,11,11 and so on. But static variable will print the incremented value in each function call e.g. 11, 12, 13 and so on.

C++ Storage Classes
Storage Classes





Constants c++ programming language.

C++ Programming Tutorial

Constants c++ programming language.


Constant does not change during the execution of the program.Constants refer to fixed values that the program may not modify and they are called literals.

How to declare constant? Let's look at the first of its various methods with examples. In which we will declare constant variable using const keyword.






#include <iostream> using namespace std; int main() { const float PI = 3.14; cout<<"Value of PI "<<PI; return 0; }
Output:
Value of PI 3.14

If you talk about constant in the above program, now you can not change the value of PI = 3.14 again anywhere in the program. If you remove the const keyword then the value of the variable will never change the value. Can not change run time and compile time.

#define constants

#include <iostream> using namespace std; #define PI 3.14 int main() { cout<<" Value of PI: "<<PI; return 0; }
Output:
Value of PI: 3.14

Wherever you use PI. Which you understand that where you are writing PI, you are not writing PI value 3.14, that is, when you process your code to compile, the compiler will get constant value instead of PI.




Variable Scope in C++ language.

C++ Programming Tutorial

Variable Scope in C++ language.


There are three places, where variables can be declared.





  1. Local variables.

  2. Global variables.

  3. Formal parameters.


1.Local variables.

Variables that are declared inside a function or block are local variables. They are not used outside of a function.

void function1() { int x=10;//local variable }

2.Global variables

A variable that is declared outside the function or block is called a global variable. Any function can change the value of the global variable. It is available to all the functions.

int value=20;//global variable void function1() { int x=10;//local variable }
#include <iostream> using namespace std; // Global variable declaration: int p; int main () { // Local variable declaration: int x, y; // actual initialization x = 10; y = 20; p = x + y; cout << p; return 0; }

Initializing Local and Global Variables

A local variable is not initialized by the system, you must initialize it yourself. Global variables are initialized automatically by the system. They are.

Data Type Initialize

int

0

char

'\0'

float

0

double

0

pointer

NULL

3.Formal parameters.

The identifier used in a method to stand for the value that is passed into the method by a caller.




What is Variable?

C++ Programming Tutorial

What is Variable?


The Variable is also the name of a memory location. It stores the values of data types. Its value can be changed and it can be reused many times.






Rules for the variable name.

  1. It is case-sensitive. For eg int 'a' and int 'A' these are different variables.

  2. A variable starts with any alphabet (a-z, A-Z) or underscore (_). But didn't start with a digit.

  3. A Variables can be named alphanumeric and '_'. For eg. a1 = 5, var1, var2,_var3.

  4. The variable does not allow white space.

  5. The variable name is not any C ++ keywords name.


The syntax for the Variable Declaration.

type variable_list;

The declaring a variable is given below.

int x; float y; char ch;

Here x, y and ch are variables, and int, float, char are data types.

For example:

int x; int y;

Then declare as int x, y; are Same data type variables.

int x; float y;

The declare as int x and float y. Different data type variables.

We can also provide values while declaring the variables as given below:

int x=10,y=20; //declaring 2 variable of integer type float ft=30.8; //declaring 1 variable of float type char ch='P'; //declaring 1 variable of char type

Valid variable names:

int x; int _xy; int p31; float m; float _pq; float r36; char c; char _ch; char c31;

Invalid variable names:

int 20; // A variable name didn't start with a digit. int x y; // A variable does not allow white space. int char; // A variable name is not any C ++ keywords name.

Declaration and initialization of C++ Variable.

When Variable declare, then this variable allocates memory according to the data type.After being a variable declare, it takes a Garbage Value inside itself.

Garbage Value: Garbage Value Variable is given by the Compiler.

#include <iostream> using namespace std; int main(){ int number; cout<<"Value of number : "<<number; return 0; }
Output:
Value of number : 4354190

Note: Here 4354190 is a garbage value.

#include <iostream> using namespace std; int main(){ int no1, no2, no3; cout<<"Value of no1 : "<<no1<<endl; cout<<"Value of no2 : "<<no2<<endl; cout<<"Value of no3 : "<<no3<<endl; return 0; }
Output:
Value of no1 : 4354318 Value of no2 : 2293652 Value of no3 : 4354224

Note: Here no1,no2 and no3 variables are store garbage value respectively 4354318, 2293652 and 4354224.

Variable Initialization

When Variable initializes, then this variable allocates memory, according to the data type it is. For eg. int for 2bytes (16-bit) | 4bytes (32-bit) | 8bytes (64-bit).

In variable initialization, a variable takes only one value for eg. int x = 5;

#include <iostream> using namespace std; int main() { int number1 = 5, number2 = 6; cout<<"Value of number1 : "<< number1<<endl; cout<<"Value of number1 : "<< number2; return 0; }
Output:
Value of number1 : 5 Value of number1 : 6



C++ Input/Output operation.

C++ Programming Tutorial

C++ Input/Output operation


As in c language use scanf () for input and printf () functions for output.Similarly, we use cin >> for input in c ++ and cout << for output.






Input/Output Library Header Files

Header File Function and Description

<iostream>

It is used to define the cout, cin and cerr objects, which correspond to the standard output stream, a standard input stream and standard error stream.

<iomanip>

It is used to declare services useful for performing formatted I/O, such as set precision and set.

<fstream>

It is used to declare services for user-controlled file processing.

cout (output stream)

cout => cout means console output. This is the object of the iostream class.

<< => This is called output operator, insertion operator.

#include <iostream> using namespace std; int main( ) { char array[] = "Welcome to C++ programming."; cout << "Display name : " << array << endl; }
Output:
Display name : Welcome to C++ programming.

cin (input stream)

cin => cin means console input. This is the object of the iostream class.

>> => It is called input operator, extraction operator.

#include <iostream> using namespace std; int main( ) { char name[31]; cout << "Enter your name: "; cin >> name; cout << "Your name is: " << name << endl; }
Output:
Enter your name: rama Your name is: rama

endl (End line).

The endl is used to insert a new line characters and flushes the stream.

#include <iostream> using namespace std; int main( ) { cout << "C++ programming Tutorial"; cout << " cprogramming"<
Output:
C++ programming Tutorial cprogramming End of line



How to make the first program of C ++?

C++ Programming Tutorial

C++ Input/Output operation


As in c language use scanf () for input and printf () functions for output.Similarly, we use cin >> for input in c ++ and cout << for output.






Input/Output Library Header Files

Header File Function and Description

<iostream>

It is used to define the cout, cin and cerr objects, which correspond to the standard output stream, a standard input stream and standard error stream.

<iomanip>

It is used to declare services useful for performing formatted I/O, such as set precision and set.

<fstream>

It is used to declare services for user-controlled file processing.

cout (output stream)

cout => cout means console output. This is the object of the iostream class.

<< => This is called output operator, insertion operator.

#include <iostream> using namespace std; int main( ) { char array[] = "Welcome to C++ programming."; cout << "Display name : " << array << endl; }
Output:
Display name : Welcome to C++ programming.

cin (input stream)

cin => cin means console input. This is the object of the iostream class.

>> => It is called input operator, extraction operator.

#include <iostream> using namespace std; int main( ) { char name[31]; cout << "Enter your name: "; cin >> name; cout << "Your name is: " << name << endl; }
Output:
Enter your name: rama Your name is: rama

endl (End line).

The endl is used to insert a new line characters and flushes the stream.

#include <iostream> using namespace std; int main( ) { cout << "C++ programming Tutorial"; cout << " cprogramming"<
Output:
C++ programming Tutorial cprogramming End of line



C++ Features. | सी ++ सुविधाएँ।

C++ Programming Tutorial

C++ Features.


All programs in C ++ can be written in simple English language. So that it is easy to understand and develop by the programmer.

It is the concept of moving instructions from one system to another. In the C ++ language, the .cpp file contains the source code. We can also edit this code.

When we copy the .exe file to another computer. Which has a window operating system? So it works properly. Because the basic code of the application is similar to an operating system.






C ++ provides many features which are given below.

  1. Simple.

  2. Machine Independent or Portable.

  3. Mid-level programming language.

  4. Structured programming language.

  5. Rich Library.

  6. Memory Management.

  7. Fast Speed.

  8. Pointers.

  9. Recursion.

  10. Object Oriented





Simple.

C ++ is a simple programming language in the sense that it provides a structured approach, rich set of library functions, data types etc.

Machine Independent or Portable.

The c ++ program can be executed in multiple machines. But it is not platform-independent.

Mid-level programming language.

C++ language binds the gap between machine-understandable Machine level language and High-level languages. C++ language can be used to write system programming like an operating system as well as an application program like the spreadsheet, the word processor that’s why it is called middle-level language. C++ combine the elements of high-level languages with the functionality of assembly language.

Structured programming language.

C++ is a structured programming language that we can break the program divided into parts using functions. So, it is easy to understand and modify any program.

Rich Library.

There are many functions available through the C ++ Standard Template Library (STL) that help in writing code quickly. For example, there are standard libraries for different containers such assets, maps, hash tables, etc.

Memory Management.

C ++ allows us to allocate memory of a variable or an array at run time. This is known as dynamic memory allocation. In other programming languages such as Java and Python, the compiler automatically manages memories assigned to variables.

Fast Speed.

The compilation and execution time of the C++ language is fast.

Pointers.

The memory address of Variable can be directly accessed through Pointer. The pointer is a data type like the other data type which takes an address for itself in memory. The following are some of the Pointer Value used in C ++.

Recursion.

The function in which the same function is called recursion. Recursion is a process that works like a loop. Recursion seems to be a satisfying condition so that the recursive function stops working. The Recursive Function keeps calling until its satisfaction is reached. If the recursive function is not satisfied, then there is a possibility of infinite looping.

Object-Oriented.

C ++ is an object-oriented programming language. This means that the focus on these objects is on "objects" and manipulations. Information about the work of these manipulations is passed on to the consumer of the item.