Home » » C++ Class - 02 - Variables Declaring and Intialization

C++ Class - 02 - Variables Declaring and Intialization


C++ Class - 02 - Variables Declaring and Initialization
BY: Ch. Kashif Nadeem (MCS-Virtual University Lahore)

Dear Students ...,
We are starting C++ Learning Tutorial and by keeping in mind that you do not know how to write simple and complex program. So we take start from basic programs.
Program 02 : Variable Declaration & Initialization C++?

In this program we declare three variables a, b and sum. We initialize value by using assignment operator =.
It is very simple process of adding two values and print result on the console.
See program snapshot below:

  • In this program three variables are declared of int data type. Int data type is used to store only integer values in the variables whose data type will be int. We can declare all variables in single line of same data type.
  • Value initialization is a process in C++ in which we provide value to variables at the time of declaration. Declaration and initialization can be done in one line.
  •  An important question here that why we initialize zero value to variable sum? Answer is that we want to protect sum variable from the garbage value before processing. After process the resultant value of a+b will assign to variable sum.
  • Now we can print the value of sum variable with cout function. << is called extraction brackets. simple string written within double quotes cout<<"Welcome " will print same in the program as written but <<sum will prints the value of variable sum.
See Lecture Video below

0 comments:

Post a Comment

LIKE US

Popular Posts

My FANS around the WORLD

Flag Counter