DEV Community

Pushpender Singh
Pushpender Singh

Posted on • Edited on

2

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.

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay