We are now at the 4th Semester of our study for IT-Software Development at SAIT and are currently studying Security for Software Developers. And our 1st module involves introduction to the C language.
What's the point of converting an integer pointer to an integer?
Good question. If you are given a set of codes whose signatures are outside of your authority to modify, which is common in software development field, you may face some odd situations that requires odd solutions, which in turn, raises odd questions that adds to your knowledge and experience.
If you are required to use a method that uses a pointer as a parameter, then suddenly, that same method is later being used with the real integer as a parameter and that same parameter obtained from that method is later utilized like a regular integer, it makes sense to think about how the real value being pointed at by the pointer can be recovered.
What's the point of converting an integer pointer to an integer?
Good question. If you are given a set of codes whose signatures are outside of your authority to modify, which is common in software development field, you may face some odd situations that requires odd solutions, which in turn, raises odd questions that adds to your knowledge and experience.
If you are required to use a method that uses a pointer as a parameter, then suddenly, that same method is later being used with the real integer as a parameter and that same parameter obtained from that method is later utilized like a regular integer, it makes sense to think about how the real value being pointed at by the pointer can be recovered.
So I've been googling to see whether there is already a solution to this query. Apparently, the question has been asked many times before but the solutions offered by the public are mostly concepts. Because a "pointer" is nothing but a pointer towards the location of an object in a memory. Therefore, it doesn't have any real value. It's artificial.
Since I did not want to disturb Sir Timothy Williams on a bright and sunny weekend, I am left with three things to solve this problem:
And thank God, there is a way to recover the value. So how do you convert an integer pointer to an integer? The answer is, attempting a direct conversion cannot really give you the real value that you can use right away.
You can do something like:
int* trial=getNumClassmates(trial);
int count=(int)trial;
But all it does is give you the address of that pointer. The good news is, there is still a way that you can capture the real value without direct conversion. You can do it by creating a self-replicating algorithm that runs side by side with the pointer, and calculating that run will give you the value of that pointer. Thus, the pointer's real value has been captured, which you can just assign to an integer!
See the pictures below for details of the code as well as the results.
Since I did not want to disturb Sir Timothy Williams on a bright and sunny weekend, I am left with three things to solve this problem:
- Our VMWare
- GEdit
- The Linux Terminal
And thank God, there is a way to recover the value. So how do you convert an integer pointer to an integer? The answer is, attempting a direct conversion cannot really give you the real value that you can use right away.
You can do something like:
int* trial=getNumClassmates(trial);
int count=(int)trial;
But all it does is give you the address of that pointer. The good news is, there is still a way that you can capture the real value without direct conversion. You can do it by creating a self-replicating algorithm that runs side by side with the pointer, and calculating that run will give you the value of that pointer. Thus, the pointer's real value has been captured, which you can just assign to an integer!
See the pictures below for details of the code as well as the results.