3.2.5 Variable Declaration and Initialization, Chapter3 - Object Oriented Programming in C++, HSSC-II (12th Class) Computer Science Key Point Notes

3.2.5 Variable Declaration and Initialization, Chapter3 - Object Oriented Programming in C++, HSSC-II (12th Class) Computer Science Key Point Notes

12th Class (HSSC-II) Computer SLO Based Key Point Notes

(National Book Foundation - As Federal Textbook Board, Islamabad 
Based on National Curriculum Pakistan 2023-2024 and Onward prescribed by Federal Board of Intermediate and Secondary Education, Islamabad, and All Pakistan Boards) 

{Contact WhatsApp 03339719149 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}

************************************

👉👉👉 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;

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;


👇👇👇👇👇👇👇👇👇👇👇👇


************************************
👉👉👉 Computer Science 12th Class Notes (Main Page)

************************************


************************************
Shortcut Links For:

1.  5th Class All Subjects Notes

2.  8th Class All Subjects Notes

3.  Easy English Grammar Notes



1. Website for School and College Level Physics   
2. Website for School and College Level Mathematics  
3. Website for Single National Curriculum Pakistan - All Subjects Notes 

© 2023 & onwards Academic Skills and Knowledge (ASK  

Note:  Write me in the comments box below for any query and also Share this information with your class-fellows and friends.

Post a Comment

0 Comments

cwebp -q 80 image.png -o image.webp