< C Tutorial

C variables

← Previous Next →


Variables:

Variables are simply names used to refer to some location in memory – a location that holds a value with which we are working. Size of variables depends upon data type used to define it.

Syntax :

variable_type variable_name;

Rules for defining variables in C

  • The name of a variable can be composed of letters(a-z, A-Z), digits(0-9), and the underscore character(_).
  • It must begin with either a letter or an underscore.
  • Name is case-sensitive means Upper and lowercase letters are distinct.
  • Blank spaces can't be used in variable names.

Example :

int EmployeeId;
double Salary;

Incorrect Variable names

int 9people;  //variable name can't start from number
int zben?op; //? character not allowed

Lvalues and Rvalues in C

There are two kinds of expressions in C -

  • lvalue - Expressions that refer to a memory location are called "lvalue" expressions. An lvalue may appear as either the left-hand or right-hand side of an assignment.
  • rvalue - The term rvalue refers to a data value that is stored at some address in memory. It which means an rvalue must appear on the right-hand side but not on the left-hand side of an assignment.
int employeeId = 20;  //valid statement 

10 = 20; // invalid statement, compile-time error
← Previous Next →