Skip to content

Commit e9c73e7

Browse files
committedDec 13, 2017
pointers explained
1 parent c504e6d commit e9c73e7

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed
 

‎AbstractClass.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class Anish : public Person {
2323
void intro() {//function overridden in derived class
2424

2525
cout<<"Hi I am Anish"<<endl;
26-
Person::intro(); //calling pure virtual function
26+
//Person::intro(); //calling pure virtual function
2727
}
2828

2929
};
@@ -39,6 +39,8 @@ int main() {
3939
Anish a;
4040
a.intro();
4141
getIntro(&a);
42+
a.Person::intro(); //accessing the base class intro() function, though it is a pure virtual function
43+
4244

4345
return 0;
4446
}

‎Pointer2.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include<iostream>
2+
3+
using namespace std;
4+
5+
int main() {
6+
int a=10;
7+
int *ptr=&a; //ptr refers a and stores its mem address
8+
9+
cout<<a<<endl; //value of a
10+
cout<<&a<<endl; //mem address of a-Hexadecimal
11+
cout<<*&a<<endl; // value of a =10
12+
cout<<*ptr<<endl;//value of a =10
13+
cout<<&ptr<<endl;//address of ptr variable
14+
cout<<&*ptr<<endl;//address of a as value of *ptr=10 and address of 10 is add of a
15+
cout<<*&ptr<<endl;// address of a, as &ptr is address of ptr and ptr stores the mem address of a as value
16+
return 0;
17+
}

‎VirtualFuncInheritence.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ void getIntro(Person *p)
3939
}
4040

4141

42-
int main() {
42+
int main()
43+
{
4344

4445
Person *p1,*p2;
4546
Anish a;

0 commit comments

Comments
 (0)
Please sign in to comment.