C++ - Variables

pushpend3r

Pushpender Singh

Posted on December 15, 2019

C++ - Variables


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:-

  1. https://data-flair.training/blogs/variables-in-c-and-c-plus-plus/
  2. http://www.cplusplus.com/doc/tutorial/variables/
  3. 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.

💖 💪 🙅 🚩
pushpend3r
Pushpender Singh

Posted on December 15, 2019

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related