Hello,
I have a simple question. I've been writing a function that shows me the current address of a variables memory. So far there are multiple addresses when pointing to each of the pointers.
My code is below, and was wondering if this is the correct route to finding the address of the variable:
I do know if you get control of **arg you can write information to it. Like [*(float *)*arg] would allow you to write a floating point to your memory address.Code:void memoryAddress(const char *format, ...) { int cmd, **arg = (int **)&format + 1; while (*format) { if (format[0] != '%') { format++; continue; } cmd = format[1]; format += 2; switch( cmd ) { case 'i': case 'd': case 'u': case 'c': case 'f': case 'g': case 's': printf("0x%p\n", (void *)arg); // address of data break; } arg++; } } int main() { float myFloat = 0.0f; char str[] = {"Hello"}; memoryAddress("%s %g", str, &myFloat); return 0; }
I just want to confirm this is all correct. Though if I display [*arg] or [arg] I get other address results. Does anyone know the difference between the three results? [**arg] — [*arg] — [arg]
Edit: No this is not homework, im just curious about the different memory address results
Thank you for your time,
- Stack Overflow