pointer notes
==================
#include<iostream>
using namespace std;
int main(){
//int a;
//cout<<&a<<endl; // & address of operator -- memory location represents
int a = 10;
int *b;
b = &a;
cout<<&b<<" - b pointer ka address ya memory location"<<endl; //
45df5456 b pointer ka address ya memory location
cout<<*b<<" - a ki value "<<endl;
cout<<b<<" - a varible ki memory location jo b pointer me store hai"<<endl;
return 0;
}
----------------
//pointer with arrays and pointer arithmetic
#include<iostream>
using namespace std;
int main(){
int marks[5] = {50,85,68,85,69};
int *ptr;
ptr = &marks[0]; // array ke first memory location ka address
cout<<ptr<<endl; //5dfdf5d5f454
cout<<*ptr<<endl; // first element ki value 50
cout<<*(ptr+2)<<endl; //68
cout<<*(ptr-2)<<endl; // gives garbage value
return 0;
}
----------------------------
//pointer to pointer
#include<iostream>
using namespace std;
int main(){
int value = 20;
int *ptr1;
int *ptr2;
ptr1 = &value;
ptr2 = ptr1;
cout<<ptr1<<" memory address value ka"<<endl; // 54dfdf5454f5d memory
address value ka
cout<<&ptr1<<" memory address *ptr1 ka"<<endl;
cout<<*ptr1<<" &value ye momory location pe jo value hai 20 wo ayegi"<<endl;
//--------------------------------
cout<<ptr2<<" memory address *ptr1 ka"<<endl;
cout<<&ptr2<<" memory address *ptr2 ka"<<endl;
cout<<*ptr2<<" memory address value ka"<<endl;
return 0;
}