Variables in C

Variables in C

 Variables in C


A variable is nothing but a name given to a storage area that our programs can manipulate. Each variable in C has a specific type, which determines the size and layout of the variable's memory; the range of values that can be stored within that memory; and the set of operations that can be applied to the variable.

The name of a variable can be composed of letters, digits, and the underscore character. It must begin with either a letter or an underscore. Upper and lowercase letters are distinct because C is case-sensitive.


There are some rules to choosing a variable name

  • A variable name can consist of Capital letters A-Z, lowercase letters a-z, digits 0-9, and the underscore character.
  • The first character must be a letter or underscore.
  • Blank spaces cannot be used in variable names.
  • Special characters like #, $ are not allowed.
  • C keywords cannot be used as variable names.
  • Variable names are case sensitive.
  • Values of the variables can be numeric or alphabetic.
  • Variable type can be char, int, float, double, or void.

Based on the basic types explained in the previous chapter, there will be the following basic variable types −

Sr.No.Type & Description
1

char

Typically a single octet(one byte). It is an integer type.

2

int

The most natural size of integer for the machine.

3

float

A single-precision floating point value.

4

double

A double-precision floating point value.

5

void

Represents the absence of type.

Some examples are −

extern int d = 3, f = 5;    // declaration of d and f. 
int d = 3, f = 5;           // definition and initializing d and f. 
byte z = 22;                // definition and initializes z. 
char x = 'x';               // the variable x has the value 'x'.

Previous                                                                                       Next


0 Response to "Variables in C"

Post a Comment

Iklan Tengah Artikel 1

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel