While naming pointers we generally have two approaches.
After data type and pointer symbol "*
", for a name we can start with a lowercase letter and concatenate it with a uppercase letter.
Another variant is start with uppercase letter and continue with uppercase letter.
In first option we can start with ptr as prefix, and in second option ptr will be suffix for pointer name.
Just make sure that pointer name describes clearly where it is pointing.
Just stick to one approach that works for you:
#include <iostream>
using namespace std;
int main() {
int number = 1000;
int *ptrNumber = &number;
int *NumberPtr = &number;
cout << ptrNumber << endl;
cout << NumberPtr << endl;
return 0;
}
Result:
0x6dfee4
0x6dfee4
Process returned 0 (0x0) execution time : 0.126 s
Press any key to continue.
C++ gives you freedom to use a pointer symbol "*
" in three ways. Use one that looks "clearer" to you.
A lot of discussions exist on internet about which way is correct, but just make sure that you use one approach you like all the time.
#include <iostream>
using namespace std;
int main() {
int number = 1000;
int *ptrNumber = &number;
int * ptrNumber2 = &number;
int* ptrNumber3 = &number;
cout << ptrNumber << endl;
cout << ptrNumber2 << endl;
cout << ptrNumber3 << endl;
return 0;
}
Result:
0x6dfee0
0x6dfee0
0x6dfee0
Process returned 0 (0x0) execution time : 0.049 s
Press any key to continue.
No comments:
Post a Comment