Variables Declaration in C | How to declare variables in a C program | Types of Variables in C | Variable initialisation | Programming tutorials | C programming | C programming tutorials
Hello guys,in the last article we learn about how to run our first program in C, now we are going to know about "VARIABLES" & "VARIABLE DECLARATION."
Variable is a name given to the memory location that stores some kind of data.Its value can be changed and it can be also used several times. Basically, A variable contains some data which can be used in the program for different purposes. There are several rules for naming a variable in a C program:-
- Variable names should always start with an English Alphabet.
- Variable name can contain digits, but the digits should not be used in the beginning of the variable name.
- Variable name should not contain any special symbols except "_" (Underscore).
The Syntax for declaring a variable in a C program is:-
datatype VariableName=value;
Here "datatype" is the type of the data that the variable will store in it, "VariableName" is the name given to the variable by the user according to the rules given above and "value" is the value assigned to the variable by the user. However, the "value" part is optional as the value of the variable can be assigned later in the program.
Variable Declaration:-
Assigning the datatype and the variable name to a variable in the program for the first time is known as variable declaration. A variable needs to be declared only once in a C program. During declaration, the user may or may not assign the value of the variable to it.
For example:- int x;
Variable Initialization:-
Assigning the value to a variable is known as Variable initialization in a C program. Variable initialization can only be done after the variable is declared. Initialization to a variable is allowed multiple times in a C program. However, the initialization can be done in the same line in which the variable is declared or in the further part of the program as per the user choice.
For example:- int x=10; Or
x=10;
Types of Variable in C :-
There are many types of variables in C-
1. Local Variable 2. Global Variable
3. Static Variable 4. Automatic Variable
5. External Variable
We will learn about types of Variables in detail later on.
In our next blogs, we will learn about the different datatypes which are used in the C language and their operations. If you have any suggestion / Advice for us, feel free to let us know in the comment section. We will be happy enough to know your feedback. Also, your appreciation will motivate us to add more to this blog.
Till then, Stay safe & Stay healthy. Have a nice day!!
Comments
Post a Comment