A variable is just a named area of storage that can hold a single value (numeric or character). The C language demands that you declare the name of each variable that you are going to use and its type, or class, before you actually try to do anything with it. The Programming language C has two main variable types
Local Variables
Check following example's output
Here ++ is called incremental operator and it increase the value of any integer variable by 1. Thus i++ is equivalent to i = i + 1; You will see -- operator also which is called decremental operator and it idecrease the value of any integer variable by 1. Thus i-- is equivalent to i = i - 1; Global VariablesGlobal variable is defined at the top of the program file and it can be visible and modified by any function that may reference it. Global variables are initalised automatically by the system when you define them!
If same variable name is being used for global and local variable then local variable takes preference in its scope. But it is not a good practice to use global variables and local variables with the same name.
i in main function is global and will be incremented to 5. i in func is internal and will be incremented to 11. When control returns to main the internal variable will die and and any reference to i will be to the global. |
Variable Types
Subscribe to:
Post Comments (Atom)
C Tutorials
- C - Programming HOME
- C - Basic Introduction
- C - Program Structure
- C - Reserved Keywords
- C - Basic Datatypes
- C - Variable Types
- C - Storage Classes
- C - Using Constants
- C - Operator Types
- C - Control Statements
- C - Input and Output
- C - Pointing to Data
- C - Using Functions
- C - Play with Strings
- C - Str Datatypes
- C - Working with Files
- C - Bits Manipulation
- C - Pre-Processors
- C - Useful Concepts
0 comments:
Post a Comment