Variables
A variables is nothing but a name given to 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 value that can be stored within that memory; and the set of operations that can be applied to the variable.
Rules for naming a variable
  • Every variable name should start with alphabets or underscore (_)
  • Variable name can consist of Capital letter A-Z, lowercase letter a-z , digits 0-9 and the underscore character
  • Blank spaces cannot be used in variable names.
  • Instead (_) character no special character are allowed in C variable .
  • C keywords can not be used as variable names.
  • Variable names are case sensitive.
  • Maximum length of variable is 8 characters  depend on compiler and operation system.
Variable Definition in C 
Syntax: Type variable-name; 
Or
Type variable_name, variable_name, variable_name;
Example:
Int width, height=5;
Char letter=’A’;
Float age, area;
Double d;
/*actual initialization*/
Width = 10;
Age = 26.5;
 Variable Assignment
Variable assignment is process of assigning a value to variable.
Example: 
                Int width = 54
                Int age = 29;

Scope of variable
In C language, a variable can be either of global or local scope.
Global variable
                       Global variable are defined outside of all the functions, generally on top of the program. The global variable will hold their value throughout the life-time of your program.
Local variable
                    A local variable is declared within the body of a function or block. Local variable only use within the function or block where it is declare.
Example of Global and local variable
#include<stdio.h>
#include<conio.h>
Int a;// global variable
Void main()
{
Int b;//local variable 
a=10, b=20;
printf(“value  of a : %d”a);
printf(“value of b : %d”,b);
getch();
}
Output
Value of a :10
Value of b : 20

Constants
  • Constants are like variable, except that value never changes during execution once defined.
  • Constants are also called literals. 
  • Constants can be any of the data types.
  • If is considered best practice define constants using only upper-case names.
Constant Definition in C
Syntax: const type constant_name;
Example:
#include<stdio.h>
Void main()
{
Constant SIDE=10;
Int area;
area=SIDE*SIDE;
printf(“The area of the square with side:%d is : %sd sq. unirs”
.SIDE, area );
}
Type of constant in C language
 Primary Constant 
Integer Constant
Its refers to sequence of digits.
Example:
15, -245, 0, 97688, +24, 037, 0 ×6
Real constant
The numbers containing fractional parts like 99.25 are called real of floating points constant.
Character constant 
A single character enclosed within a pair of single quote marks.
Example: “x” , “5”, “;”
Backlash character constant
C support some special backlash constant that are used in output functions.  


CONATANTS MEANING
/b back space
/f form frre
/n new line
/r carriage return
/t horizonral tab
/v vertical tab
/' single quote
/" double quote
// backlash
/0 A collection of related variables of the same and/ or different data types.
String constant
 A string constant is a sequence of character enclosed within quotes. Example: “HELLO !”, “2005”, “2=1”
 Secondary Constant
  • Array
  • Pointer
  • Structure
  • Union
  • Enum

Post a Comment

Please Do Not Enter Any Spam Link In The Comment Box.

Previous Post Next Post
× DMCA!Bilimtook.com is in compliance with 17 U.S.C. * 512 and the Digital Millennium Copyright Act (DMCA). It is our policy to respond to any infringement notices and take appropriate actions. If your copyrighted material has been posted on the site and you wanna this material removed, Contact Us