A variable in simple terms is a storage place which has some memory allocated to it.
Think of it like a box where you can put your data into.
Terms
Declaration:- specify variable name and it’s data type.
Definition:- Declaration + assign memory to it.
Initialization:- put value into the box.
Datatype:- size of the box
Variable Name: name of the box.
How to Create a Variable?
- First Method
int a = 12;
/*
int = datatype
a = variable name
12 = value
*/
- Second Method
int a{12}; // called uniform initialization
- Third Method
int a(12); // called constructor initialization
Note:- All these three called definition + initialization of a variable.
References for more information:-
- https://data-flair.training/blogs/variables-in-c-and-c-plus-plus/
- http://www.cplusplus.com/doc/tutorial/variables/
- https://www.geeksforgeeks.org/c-data-types/
That's it guys. Have a good day.
If you find anything incorrect or know more about it let me know in the comments.
Top comments (0)