Data types and variables

Among the very first concepts you will be learning in any programming language is data types and variables. Also if not understood properly these two concepts can become one of the major roadblocks for you to learn programming. In this tutorial our goal is to help you conceptually understand the meaning of data types and variables.

What is a data type?

Let’s start by taking an example. One of your friends calls you to ask if he can park his car and bike at your place and wants to know if you have space for both these vehicles at home. Suppose a car takes up 8 ft * 5 ft space and a bike takes up 6 ft * 3 ft space. According to how much space is available at your house you say yes or no to your friend. Same is the concept of data types. Each data element consumes different amount of space in the RAM depending on its type. When you ask the computer to give you some space in the RAM to store your data you will have to specify the type of data you want to store so that the required amount of memory space can be allocated.

The common data types you will find in all programming language are

  1. Int - to store integer type data
  2. Char - to store character type data
  3. Float - to store decimal numbers
  4. Bool - to store Boolean type data
  5. String - to store English sentences

Also all programming languages give the programmer power to create his/her own data types by combining the pre defined data types. These new data types which a programmer creates are called user defined data types.

Variables

Let’s start by taking an example. Suppose you have a big shopping complex in your city with a multilevel parking in the basement. The parking is so big that it can accommodate thousands of cars at one time. You go for shopping and park your car in the parking and proceed for shopping. When you come back you realize that you are not able to remember where you parked your car. Now you go to one of the security guards and ask him how you can find your car. The security guard asks – Did you note down the number of the parking spot where you parked our car? You try for some time and you are able to recall the number of the parking spot and you find your car. The parking spot can be thought of a variable – its number does not change but the cars which stand there keep changing.

Same is the concept of variables in programming. For storing some data in the RAM you ask the computer for some memory to be allocated according to the type of your data. In order to read or write data at that memory location you have to remember its number or address. But because it is difficult for programmers to remember the number or address of every variable, you have the option to choose names for your variables. You tell the computer the name of the variable and it will find out its address and you can then read or write data at that memory location.

Different programming languages use different syntax to create variables. In some programming languages you have to specify the data type of the variable at the time you are creating that variable where as in some programming languages the data type of the variable is known when the data is assigned to the variable. We will discuss the syntax of declaring and using variables in different programming languages in their respective E-Classrooms.

Quick Links

E-Magazines

@

Total Followers
Study Group Created
Study Group Joined
Following Teacher
Following Organization
Blog Articles Added
Questions Asked
Questions Answered
Jobs Posted
Total Members in Group
Questions asked by members
Tasks added in this Group

Please wait..

Ok

Login to Open ESchool OR Create your account    Login   SignUp