Posted By:
11 Jun, 2013 12:10 am PDT

Variables in C and C++

What is a variable? Explain variables and its types

Each variable in C has a specific type, which determines :

  1. the size and layout of the variable's memory;
  2. the range of values that can be stored within that memory;
  3. and the set of operations that can be applied to the variable.

Please watch the video for details....

Was it useful?  

We all live in apartments, right ?

The size of the apartment do vary from place to place and person to person.

A large apartment can accomodate many people while , a small apartment can accomodate less.


Variables : These store the input values, these are nothing but named memory locations. The type of the variable must be declared such as , Large apartment or small apartment . Likewise , the terms used to indicate the size of variable are called data types.


Variable types are :

Char:       Typically a single octet (one byte). This is an integer type

Int:           The most natural size of integer for the machine

Float:       A single-precision floating point value.

Double:    A double-precision floating point value.

Void:       Represents the absence of type.



int i, j, k;

char c, ch;

float f, salary;

double d;

 You must notice the way variables are declared .

1) A Variable name consists of any combination of alphabets, digits and underscores.

2) The first character of the variable name must either be alphabet or underscore.

3) It should not start with the digit.

4) No commas and blanks are allowed in the variable name.

5) No special symbols other than underscore are allowed in the variable name.

Have a look at the program attached. If you execute it , you will understand the size of each variable type.


Was it useful?  

Please login to reply to this problem.