In this session, you are going to learn about variables and IO operations. This is fairly easy to understand and once you get hold of it, then whatever comes next, will be easy for you. Variables are like containers of information. However, a variable is specific container of information. For instance, if a variable has been specified to hold numbers, it will only hold numbers. Once defined, variable cannot change its type. Lets get started with this to understand in detail.
Lets design a program that adds two numbers. For this, you will have to ask one number from user, store it somewhere, ask another, store it again somewhere, add the two, and display the result. Fairly easy, isn't it? In order to do this, you will have to define three variables. The first one will hold the first number, second one will hold second number, and the third one will hold the addition of two. In order to make this simple, for now, lets not allow the user to enter decimals. This program will only allow whole numbers. For this, we have to define variables as 'integers'. When we define a variable as integer, it only allows user to type in numbers and not decimals. We can define the variables like this:
int value1;int value2;int sum;