Variable 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
- 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’
- 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|
Rules for constructing variable names
- “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:
|Character Constant Meaning|
|\n New line (Line break)|
|\t Horizontal Tab|
|\f Form feed|
|\a Alert (alerts a bell)|
|\r Carriage Return|
|\v Vertical Tab|
|\? Question Mark|
|\' Single Quote|
|\'' Double Quote|
Example codes on escape sequences:
char str=”naresh tech”;