Lorem ipsum dolor sit amet, consectetur adipiscing elit. Test link
Posts

3.2 Variable scope

1 min read
Image result for Variable scope

refers to where variables is declared.

It can be Inside a function or a block which is called local variables, In the definition of function parameters which is called formal parameters or Outside of all functions which is called global variables.

Global variables

Global variable are declared outside any functions, usually at top of program. they can be used by later blocks of code:
int g; //global
int main(void)
{
g = 0;
}

Local variables

Variables that are declared inside a function or block are local variables. The scope of local variables will be within the function only. These variables are declared within the function and can't be accessed outside the function.
void main()
{
int g; //local
g=2;
cout << g;
}

                      3.3 Constants - Literals          NEXT >>

You may like these posts

  •   A switch statement is used instead of nested if...else statements. It is multiple branch decision statement of C++. A switch statement tests a variable with list of val…
  • A function is a group of statements that together perform a task. All C programs made up of one or more functions. There must be one and only one main function. You can divide up…
  •   while loop The while loop calculates the expression before every loop. If the expression is true then block of statements is executed, so it will not execute If the condi…
  •   Break statement Break statement is usually used to terminate a case in the switch statement. Break statement in loops to instantly terminates the loop and program contr…
  • if statement An if statement contains a Boolean expression and block of statements enclosed within braces. Structure of if statement if (boolean expression ) /* if expression …
  • C (and by extension C++) comes with a built-in pseudo-random number generator. It is implemented as two separate functions that live in the cstdlib header: srand() sets the initi…

Post a Comment