03-Overview of C++ (Part 2)
03-Overview of C++ (Part 2)
03-Overview of C++ (Part 2)
• Data type
• Arrays
• Parameter passing
Simple
Integral
Simple
• Example:
int num[5];
//this is a static array
• In Java:
int [ ] arr; //declares array & creates reference only
arr = new int [ 5 ] ; //creates the actual array
• General syntax:
• Example:
list [3] = 10;
list [6] = 35;
list [5] = list [3] + list
[6];
• The statement:
int list[10] = {0};
declares list to be an array of 10 components
and initializes all of them to zero
• The statement:
int list[10] = {8, 5, 12};
declares list to be an array of 10 components,
initializes list[0] to 8, list[1] to 5, list[2] to 12 and
all other components are initialized to 0
• Solution:
• Solution:
• Example:
double sales [10][5];
• Syntax:
• Example:
sales [5][3] = 25.75;
void grow(int& x) {
x= x+ 1;
cout << "grow age is " << x<< endl;
}
int main() {
int age = 20;
cout << "main age is " << age << endl;
grow(age);
cout << "main age is " << age << endl;
return 0;
}
CT077-3-2-DSTR Data Structures 22
Example Program - 2
void main() {
int value= 20;
inc (value);
cout << "value is " << value << endl;
dec (value);
cout << "value is " << value << endl;
}
CT077-3-2-DSTR Data Structures 23
Example Program - 3
• Reference parameter:
– Received address leads to memory space of the
corresponding actual parameter
– Changing reference parameter affects the actual
parameter
1 2 3 4 5
10 9 8 7 6
11 12 13 14 15
20 19 18 17 16
• Data type
• Arrays
• Parameter passing
Overview of C++
• Pointers
• Passing parameters to functions using pointers
• Dynamic Memory Allocation