Computer Science SLO Based Key Point Notes
👉👉👉 Computer Science 12th Class Notes (Main Page)
************************************
Unit 3: Object-Oriented Programming in C++
3.2.5 Variable Declaration and Initialization
Variable Declaration
- The process of specifying the variable name and its data type is called variable declaration.
- C++ is a typed language which means that all variables must be declared before they are used in the program.
- C++ compiler will give an error if an undeclared variable is used in a program.
The general syntax to declare a variable is:
data_type variables;
where “type” specifies the data type of variable which may be int, float, double, char, etc. “variables” specify the list of variable names of the same data type separated by commas.
Example:
int sum;
The above declaration statement tells the compiler that the variable name is “sum” and its data type is “int”.
A list of variables of the same data type can be declared in a single declaration statement i.e.
float a, b, c, d, e;
- The process of specifying the variable name and its data type is called variable declaration.
- C++ is a typed language which means that all variables must be declared before they are used in the program.
- C++ compiler will give an error if an undeclared variable is used in a program.
data_type variables;
where “type” specifies the data type of variable which may be int, float, double, char, etc. “variables” specify the list of variable names of the same data type separated by commas.
int sum;
The above declaration statement tells the compiler that the variable name is “sum” and its data type is “int”.
A list of variables of the same data type can be declared in a single declaration statement i.e.
float a, b, c, d, e;
Variable Initialization
- The process of assigning a value to a variable at the time of declaration is known as variable initialization.
- The equal sign “=“ is used to initialize a variable.
- When a variable is declared, the compiler allocates memory location which contains some data that is meaningless for the program. It is known as garbage value which may produce unexpected results.
- All variables should be initialized to avoid this problem.
- The syntax of initializing a variable is as follows:
Data_type variable_name = value;
Example:
int n = 100;
float average = 34.55;
- The process of assigning a value to a variable at the time of declaration is known as variable initialization.
- The equal sign “=“ is used to initialize a variable.
- When a variable is declared, the compiler allocates memory location which contains some data that is meaningless for the program. It is known as garbage value which may produce unexpected results.
- All variables should be initialized to avoid this problem.
- The syntax of initializing a variable is as follows:
int n = 100;
float average = 34.55;
👇👇👇👇👇👇👇👇👇👇👇👇
************************************👉👉👉 Computer Science 12th Class Notes (Main Page)
************************************
(National Book Foundation - As Federal Textbook Board, Islamabad Based on National Curriculum Pakistan 2026-2027 and Onward prescribed by Federal Board of Intermediate and Secondary Education, Islamabad, and All Pakistan Boards)
(National Book Foundation - As Federal Textbook Board, Islamabad
Based on National Curriculum Pakistan 2026-2027 and Onward prescribed by Federal Board of Intermediate and Secondary Education, Islamabad, and All Pakistan Boards)
{Contact WhatsApp # +923339719149 for Class-XII Computer Science Complete SLO-Based Key Points notes in pdf format as well as in PowerPoint Presentation for preparing/delivering the Lectures}
Note: Write me in the comments box below for any query and also Share this information with your class-fellows and friends.
0 Comments
Note: Write me in the comments box below for any queries and also Share this information with your class-fellows and friends.