Prashant | Thu, 11 Jun, 2020 | 118
What are variable and what are identifiers to learn about this visit :- Click here
As we know that variables are the name of memory blocks which are used to store values, in this tutorial we will learn how to declare local and global variables what are their scopes in C language?
Before learning about the local variable, we should learn about the function block and function parts. There are two parts of the function block (block means region of the function between curly braces in C)
Local variables are the variables which are declared or defined within the declaration part of the function block.
These variables have local scope to that function only, in which they are declared. They cannot be accessed outside of the function.
Global variables are the variables which are declared or defined below the header files inclusion section or before the main () function.
These variables have global scope to the program in which they are declared. They can be accessed or modified in any function of the program.
// Global variable
float a = 1;
void my_test() {
// Local variable called b.
// This variable can't be accessed in other functions
float b = 77;
println(a);
println(b);
}
void setup() {
// Local variable called b.
// This variable can't be accessed in other functions.
float b = 2;
println(a);
println(b);
my_test();
println(b);
}
1. Introduction And Getting Started With C
3. Why We Should Use C Language
4. Applications Of C Programming
5. Basic Rules For Writting C Program
8. Tokens In C
9. Difference Between Int Main And Void Main
11. Variables In C
13. Difference Between Local And Global Variable
14. Difference Bwtween Auto / Extern / Static Variable
15. Constant In C
16. How To Access Global Variable Using Extern Keyword In C
17. Exit And Return Staterment In C
18. Print Float Value Upto N Decimals In C Programming
19. How To Print Multiline Message Using Single Printf In C Programming ?
20. What Value Returned By Scanf Function In C Language ?
21. What Value Is Returned By Printf And Scanf In C