0% found this document useful (0 votes)
14 views2 pages

Introduction To Variables: Variable Declaration

The document provides an introduction to variables in C++, explaining their purpose as storage locations for data and the memory requirements for different types. It details how to declare variables, including the syntax and examples, and emphasizes the importance of variable initialization. Additionally, it outlines the rules for defining variables, such as naming conventions and case sensitivity.

Uploaded by

yisex18134
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views2 pages

Introduction To Variables: Variable Declaration

The document provides an introduction to variables in C++, explaining their purpose as storage locations for data and the memory requirements for different types. It details how to declare variables, including the syntax and examples, and emphasizes the importance of variable initialization. Additionally, it outlines the rules for defining variables, such as naming conventions and case sensitivity.

Uploaded by

yisex18134
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Introduction to Variables

A variable is a storage place that has some memory allocated to it. It is used to store

some form of data. Different types of variables require different amounts of memory.

Variable Declaration

In C++, we can declare variables as follows:

● data_type: Type of the data that can be stored in this variable. It can be int, float,

double, etc.

● variable_name: Name given to the variable.

data_type variable_name;

Example: int x;

In this way, we can only create a variable in the memory location. Currently, it doesn’t

have any value. We can assign the value in this variable by using two ways:

● By using variable initialization.

● By taking input

Here, we can discuss only the first way, i.e., variable initialization. We will discuss the

second way later.

data_type variable_name=value;

Example: int x = 20;

Rules for defining variables in C++

1
● You can’t begin with a number. Ex- 9a can't be a variable, but a9 can be a

variable.

● Spaces and special characters except for underscore(_) are not allowed.

● C++ keywords (reserved words) must not be used as a variable name.

● C++ is case-sensitive, meaning a variable with the name ‘A’ is different from a

variable with the name ‘a’. (Difference in the upper-case and lower-case holds

true).

C++ Keywords

You might also like