Page Stats
Visitor: 431
Local Variable
A variable that is declared inside the function or block is called local variable.
Example 1: Local varible
void show(); void main() { int a=10; //Local variable printf("Value inside main function is:\n"); printf("A = %d\n",a); void show(); getch(); } void show() { int a=20; //Local variable printf("Value outside main function is:\n"); printf("A = %d\n",a); }
Value inside main function is:
A = 10
Value outside main function is:
A = 20
A = 10
Value outside main function is:
A = 20
Reference variable
Reference variable refers to another variable, it does not occupy memory instead it refer to another variable. Any changes made to reference variable or refered variable, reflect to one another.
Example 2: Reference varible
void main() { int a=10; int &b=a; //b is refered to a clrscr(); printf("A=%d\n",a); printf("B=%d\n",b); a=20; printf("A=%d\n",a); printf("B=%d\n",b); b=30; printf("A=%d\n",a); printf("B=%d\n",b); getch(); }
A=10
B=10
A=20
B=20
A=30
B=30
B=10
A=20
B=20
A=30
B=30