It's highly unlikely that this has anything whatsoever to do with ESP32 and is more of a second-week computer science question.
Professionals work very hard to solve this problem by never HAVING this problem. Seriously.
In real systems, data moves, is accessed by different CPUs, is accessed by different CPU types, is reallocated, may be modified by interrupts, or may be eaten by a grue between the time that reference is converted to a hexy-looking thing and the time you hope to need it again. It's not like you can put it in a protobuf or a network connection or a tape backup or a CD or, well, much of anything and expect to DO anything with it. A valid pointer on your phone is simply meaningless on the Bluetooth stack in your earbuds or radios on the cellular network or the GPU pushing around pixels or whatever. It may not be suitably aligned, the datum may have been freed or, worse, reallocated. Thus, pros just don't DO this conversion often.
Still, the most literal answer to the question that you're asking (well, as best I can guess, since your actual question is quite nonsensical even once getting past the "don't do that" admonitions) is something like using the sprintf/scanf family.
Code: Select all
➜ /tmp cat x.cc
#include <stdio.h>
#include <assert.h>
int main(void) {
int number = 34567890;
printf("Number is %d. Address of number is %p\n", number, &number);
char buf[32];
int rval = snprintf(buf, sizeof(buf)-1, "%p", &number);
assert(rval > 0);
printf("buf[] is this %s\n", buf);
int* number_ptr = NULL;
int result = sscanf(buf, "%p", &number_ptr);
assert (result > 0);
printf("Content of number_ptr is %p\n", number_ptr);
// So when we dereference that number, we get...
printf("Rehydrating the dehydrated number, we get %d\n", *number_ptr);
}
➜ /tmp c++ -Wall --std=c++23 x.cc -o x && ./x
Number is 34567890. Address of number is 0x16f9d6c00
buf[] is this 0x16f9d6c00
Content of number_ptr is 0x16f9d6c00
Rehydrating the dehydrated number, we get 34567890
Ibernstone is (as usual) correct: your question is just malformed. You're askign for engineering-grade help for intro-level materal, but you're not even asking that effectively.
Of course, in post-80's code, that might be [io]stream, stringstream, std::print, std::scanner, or a hundred other things, but I'm not going to type a hundred answers to a question that you're probably not actually asking anyway.
But while I'm being preachy, three more tips:
1) Don't ignore compiler warnings/errors. At your level, ask for all you can get (-Wall, -Wextra) and fix them.
2) Take the time to really get your head around pointers. If you're in the C/C++ family, especially embedded, few concepts will be more universal. People keep promising unicorns that will shield you from big, scary, mean old pointers, but understanding how memory and memory management REALLY REALLY works - no matter how many times "new" languages promise you they can protect you from getting sawdust under your nails - is absolutely a primary employable skill. Blow that in an interview (with me), and the interview is over.
3) Don't paste a picture of text. Learn to copy and paste, so it'll show up in search, can be formatted, annotated, can be read by low-vision readers, etc. You're going to spend the rest of your life copy-pasting code from here to there, errors into a search box, boilerplate into an editor, (hopefully, eventually) coworker praise into a performance review, etc. Taking a picture of words is just lazy.