C++ Variable

A variable is a name of memory location. It is used to store data. Its value can be changed and it can be reused many times.

It is a way to represent memory location through symbol so that it can be easily identified.

Let's see the syntax to declare a variable in C++

int a;

variable name is ‘a’

variable type is “int” means it is going to store integer type values only like numbers -1, 0, 1

Other Examples

char c; //for character values like ‘a’, ‘b’

float f; //used to store floating point/ decimal values like “1.004”

Declaring two variables together

int a=5,b;

Rules for defining variables

A variable can have alphabets, digits and underscore.

A variable name can start with alphabet and underscore only. It can't start with digit.

No white space is allowed within variable name.

A variable name must not be any reserved word or keyword e.g. char, float etc.

Valid Variable Names-

1. int a;

2. int _ab;

3. int a30;

Invalid Variable Names-

1. int 4; //Variable Name can’t be only INT

2. int x y; //Space between variable Name – Not Allowed

3. int double; //double is a keyword, So Not Allowed

Move to Next Page


Previous Page Next Page

Any Doubt ? Feel free to write a comment

Download C++ Projects

Join us on LinkedIn – Great Place of Networking

Follow us on More Together – Facebook for regular updates

Mandatory to join Telegram group for regular job updates

Mandatory to join whatsapp group for regular job updates

Other C++ Topics

For Other Tutorials – Click Here

11 views0 comments

Related Posts

See All

Number to Character Conversion in C++

Program to implement Number to Character Conversion in C++ Firstly see what we are going to do ? Like this 0 - zero 1 – one 2 – two 3 – three 4 – four 5 – five 6 – six 7 – seven 8 – eight 9 – nine How

Factorial of a number in C++

In this tutorial we are going to see how to find a factorial of number using C++ program Firstly let’s see a example to understand it better n! = n + (n-1) + (n-2) ! n>=1 3! = 3 *2*1 = 6 Program to fi

Fibonacci Triangle in C++

Program to implement Fibonacci Triangle in C++ #include <iostream> using namespace std; int main() { int a=0,b=1,i,c,n,j; cout<<"Enter the limit: "; cin>>n; for(i=1; i<=n; i++) { a=0; b=1; cout<<b<<"\

Info © Copyright 2020-21 Fresher Side. All rights reserved. Contact us