-
Notifications
You must be signed in to change notification settings - Fork 0
/
ollie116_new-Keyword.cpp
45 lines (37 loc) · 985 Bytes
/
ollie116_new-Keyword.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include<iostream>
using namespace std;
// GETTING USED TO THE new KEYWORD !!!
class Myclass
{
private:
int a , b;
public:
void setData(int x , int y)
{
a = x;
b = y;
}
void getData()
{
cout<<"The value of a is: "<<a<<endl;
cout<<"The value of b is: "<<b<<endl;
}
};
int main()
{
Myclass* ptr1 = new Myclass(); // INITIALIZES WITH ZERO
// ptr->setData(10,20);
ptr1->getData();
Myclass* ptr2 = new Myclass; // INITIALIZES WITH GARBAGE VALUE
// ptr->setData(10,20);
ptr2->getData();
int* ptr = new int; // INITIALIZES WITH GARBAGE VALUE
cout<<*(ptr)<<endl;
int* tpr = new int(); // INITIALIZES WITH ZERO
cout<<*(tpr)<<endl;
int* prt = new int(0); // INITIALIZES WITH ZERO BECAUSE ZERO IS PASSED AS ARGUMENT
cout<<*(prt)<<endl;
int* trp = new int(16); // INITIALIZES WITH 16 BECAUSE 16 IS PASSED AS ARGUMENT
cout<<*(trp)<<endl;
return 0;
}