I want to get the value of an integer from within a struct pointer. Simply: int cool = *(*(&(coolPtr->map)) + x); can this be simplified? The rest of the code is context. X being the index of the array.struct Cool {    int map[5];};int value (Cool* coolPtr, int x) {    return *(*(&(coolPtr->map)) + x); // Here} int main() {// TestCool* foo = new Cool;// Fillfor (int i = 0; i < 5; i++) foo->map[i] = i*4;// Checkcout << value(foo, 3); cout << endl; // 12, correctcout << value(foo, 4); cout << endl; // 16, correct
Array to function to int arithmetic
c++;pointers
You should use one of the myriad accepted standard formatting-conventions.The things which stand out like a sore thumb are the newlines you have at the beginning of your two functions, the body of your for-loop being on the same line, and of course the content of main (which somehow lost it's closing bracket) having lost one level of indentation.Maybe the last is an artifact of not checking how it looks after posting here? Having taken a look at the source, that explanation seems unsatisfying...You should avoid using namespace std; (The other line you omitted is obviously #include <iostream>). It's a plague and just biding its time to bite you later.Why is using namespace std considered bad practice?Use '\n' instead of std::endl unless you might need to flush there.You can chain uses of the stream-inserter.Don't ever allocate something dynamically without a really good reason, and then use smart-pointers.Your value-function isn't complex enough to be usefully extracted into a function in general.Still, let's dissect the expression:*(*(&(coolPtr->map)) + x);Which is:1. dereference `coolptr` and get member `map`2. take the address3. dereference (undoing last step)4. add `x`5. dereference (equal to indexing with `x` together with step 4)Equivalent:coolptr->map[x];