Introduction To Programming

Why programs ? Programming is nothing but making the computers think the same way a human thinks. Programs are made for obtaining a specific solution which can even be solved by humans which when solved by us may consume time..

Tuesday, January 5, 2010

1

#include < iostream.h >
int a=0;
int fn1()
{
return(a+=1);
}
int fn2(int a)
{
return(a++);
}
main()
{
int a=40;
cout< < a;
fn1();
cout< < a;
fn2(a++);
cout< < a;
}

output:

40

40

41

Scope of variable

#include < iostream.h >
int a=10;
main()
{
int a=2;
cout < < a < < ::a;
}

what'll be the answer.
In last post i wrote about scope of variables. It'll print local variable value 2 first and print 10. For use global variable we use scope of variable operator i.e '::' .

Global variable vs Local variable

Today i'm going to explain you about scope of variable. Score of Variable is area of variable exists.
Local Variable:

local variable exists only in certain function. Outside of that function, variable is unknown. Simply local variable is for local.

Eg: function()
{
var declaration
}
Global variable

Global variable is possessed by all function. It's exists in global level of the program. Eg:
var declaration
function();
main()
{
}