VARIABLES IN C

Om Sharma
2 min readMay 22, 2020

‘C’ programs are variables, constants, arithmetic operator etc. A variable can play an important role in C-Language. A variable in a program is a name to which you can associate a value.The variables can play different roles in a program : local variablesformal parameterglobal variabledefined during invocation of function.Those variable, which are declared within the function are called local variables because scope of these type of declaration of variables only exist ot the function in which these are defined.In above program, the variable x, y and s are local because scope of these variables are only within the function .
Inside the function —
In definition of the functions —
Outside all functions —
Actual parameter —
For example, with the name A you can associate , say a number 20, so that whenever the number A is called /used, you get the value 20.
Local variables: For example :

int add(void)
{
int x;
int y;
int s;
x = 10 ;
y = 20 ;
s = x + y ;
return(s);
}
int diff(void)
{
int x;
int y;
int d;
x = 10;
y = 20;
d = y — x;
return(d);
}

Global Variables : The scope of global variables remain in the entire program and these type of variables can be used by any piece of code. These variables hold their values

add(void). Same variables x and y are declared at the start of the function diff(void). The local variables are declared at the start of the function body. These variables can be declared within code block.

Originally published at https://c-programmer-xp.blogspot.com.

--

--