Data Structures & Algorithms

Prateek Narang

Let's Learn

  • Programming Languages

  • C++ History

  • C++ Advantages & Applications

Variables are the buckets in the memory that hold some type of data.

Variables

Variable name: A label for a memory location

Value: The something that would be stored in a variable

Storage: A place where data can be stored

Declaration: Announcing a variable (usually) at the beginning of a program

Naming convention: A set of rules about the names of variables

Assignment: Giving (setting) a variable a value

Variables

// Valid names
int topics = 3
int marks = 20
int student_1 = 5

// Invalid Names
1_student = 8;

Naming Convention

  • For variable name we can use uppercase and lowercase letters, digits from 1 to 9 and underscore(_).
  • First character must be underscore or letter.
  • C++ is strongly typed language. So every variable needs to be declare before using it

Variable Initialisation

Variables when just declared have garbage value until they are assigned a value for the first time.

We can assign a specific value from the moment variable is declared, called as initialisation of variable.

// Declare
int marks;

// Declare + Assign (Init)
int x = 10;

CODE DEMO

[Topics] C++ 01

By Prateek Narang

[Topics] C++ 01

  • 103