Variables & Identifiers


Variables is a named memory location in the computer to store the data.
Variable is a data name to a data value.

Note: Assigning names to the data is useful for further usage in the application. It is only possible to work with same kind of data when it is having unique names.

The Programming language C has two main variable types
Local Variables
  • If we declare any variable within the block or function called as local variable.
  • Local variables scope is confined within the block or function where it is defined.
  • Local variables must always be defined at the top of a block.
  • When a local variable is defined – it is not initialized by the system, you must initialize it yourself.
  • When execution of the block starts the variable is available, and when the block ends the variable ‘dies’
Global Variables
  • If we declare any variable to outside of all the functions comes under global variable.
  • Global variable is defined at the top of the program file and it can be visible and modified by any function that may reference (scope) it.
  • Global variables are initialized automatically with some default values according to its type at the time of compilation.
Data Type Default Value
int 0
char '\0'
float 0.000000

int a,b;
float f;
char ch;
void main()
int c=10,d=20;

Rules for constructing variable names
C Identifiers
  • “Identifiers” or “symbols” are the names you supply for variables, types, functions, and labels in your program.
  • Identifier names must differ in spelling and case from any keywords.
  • You cannot use keywords as identifiers; they are reserved for special use.
  • A special kind of identifier, called a statement label, can be used in goto statements.
  • The first character of an identifier name must be a non-digit.
Escape Sequence Characters (Backslash Character Constants) in C

C supports some special escape sequence characters that are used to do special tasks. Some of the escape sequence characters are as follow:

Example codes on escape sequences:
void main()
void main()
char str[20]=”naresh tech”;

Scroll to top