C Variables & Constants

C Constants

The alphabets, numbers and special symbols when properly combined form constants, variables and keywords. A constant is an entity that does not change.

C Variables

Variables in c are names which refers to a location in memory which is used to holds some value with which we are working. A variable is an entity that may change its value. In any program we typically do lots of calculations. The results of these calculations are stored in computer memory locations. To make the retrieval and usage of these values we give names to the memory locations. These names are called variables.

C Keywords

A keyword is a word that is part of C Language itself. These words have predefined meanings and these words cannot be used as variable names.

char signed break for
auto const sizeof case
if extern double struct
continue goto register enum
typedef default return static
float union do switch
volatile int unsigned else
while long void short

Types of Variables

There are two main types of variables in C: numeric variables that hold only numbers or values, and string variables that hold text, from one to several characters long.

Basic fundamental data types in C language

char Character or small integer. 1byte signed: -128 to 127
unsigned: 0 to 255
short int Short Integer. 2bytes signed: -32768 to 32767
unsigned: 0 to 65535
long int (long) Long integer. 4bytes signed: -2147483648 to 2147483647
unsigned: 0 to 4294967295
bool Boolean value. It can take one of two values: true or false. 1byte true or false
float Floating point number. 4bytes +/- 3.4e +/- 38 (~7 digits)
double Double precision floating point number. 8bytes +/- 1.7e +/- 308 (~15 digits)
long double Long double precision floating point number. 8bytes +/- 1.7e +/- 308 (~15 digits)

Java Data Types

Variables are reserved memory locations which are used to store values. Different data types are assigned to variables depending on the value it will store in memory. Java has two data types.

  • Primitive Data Type
  • Object Data Type

Primitive Data Types

Primitive data types are predefined in java and there is a unique keyword for each data type. Following are primitive data type examples.


  • 8-bit signed integer
  • Range: -128 to 127
  • Example: byte a = 50


  • 16-bit signed integer
  • Range: -32,768 to 32,767
  • Example: short a = 1050


  • 32-bit signed integer
  • Range: -2,147,483,648 to 2,147,483,647
  • Example: int a = 100000


  • 64-bit signed integer
  • Range: -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
  • Example: long a = 10000000


  • single-precision 32-bit floating point
  • should not use for precise values like currency
  • Example: float a = 453.46


  • single-precision 64-bit floating point
  • should not use for precise values like currency
  • Example: float a = 445353.46


  • 1-bit
  • possible values (true and false)
  • Example: boolean a = true


  • 16-bit single Unicode character
  • Example: char a =’A’

Reference Data Types

Reference data types are used to create and access objects. The reference variables are declared with a specific data type and it cannot be changed e.g. Car, Employee, Dog etc.

Example: Employee newEmployee = new Employee(“Jhon”);