Repository navigation
E) Pointers basic
kalinosia edited this page Mar 13, 2021
·
2 revisions
int number = 10;
cout<<&number<<endl; //output will be address of this int - 0x7ffedca8750c
int number = 10;
int *pointer = &number;
cout<<number<<endl; //number
cout<<&number<<endl; //address of number
cout<<pointer<<endl; //pointer = address of what point
cout<<*pointer<<endl; //what pointer point
cout<<&pointer<<endl; //address of pointer
OUTPUT
10
0x7ffe03da3c24
0x7ffe03da3c24
10
0x7ffe03da3c28
string value = "mata";
string *pointer = &value;
cout<<(*pointer)[2]<<endl; //-->t
int table[5]={1,2,3,4,5};
int *pointer = table; // point to table not to address
cout<<*pointer<<endl; // ==> cout<<&table<<endl;
pointer=pointer+2; // USE IN FOR LOOP EXAMPLE <------ ...;i++,pointer++){....
cout << *pointer <<endl; // (table[0]+2=table[2] => 3)
int *point_to_last = &table[2]; // while loop example
string table[3]={"mama", "dama", "kama"};
....
cout<<sizeof(string)<<endl; //size of string = 8
cout<<sizeof(table)<<endl; //size of string x how many in table (3) = 24
cout<<sizeof(table[0])<<endl; //size of first element (string size) = 8
cout<<table[0].size()<<endl; //lenght of first element = 4 (mama) <------
int elements = sizeof(table)/sizeof(string); //if string
char text[] = "hello";
int len = sizeof(text)-1; //-1 because last \0
char *pStart = text;
cout<<pStart<<endl; //--> hello
cout<<*pStart<<endl; //-->h
cout<<text<<endl; //-->hello
char *pEnd=text+len-1; //char *pEnd=pStart+len-1;
cout<<*pEnd<<endl; //-->o
cout<<pEnd<<endl; //-->o
reversing char table....https://www.udemy.com/course/free-learn-c-tutorial-beginners/learn/lecture/1747862#announcements