Is it right or optimum answer as there are other right answers as well?
Sure. There are but because the code you provided can fail, to be considered an answer you would need to add further code to check the memory allocation
So it’s a partial answer with risks.
Is the following compilation message not enough to consider the sketch above risks:?
Sketch uses 2938 bytes (9%) of program storage space. Maximum is 30720 bytes.
Global variables use 208 bytes (10%) of dynamic memory, leaving 1840 bytes for local variables.
If that is all you want your code to do, memory is not an issue.
However if you want to use that code in another context then it is as @J-M-L says a waste of memory and could cause a fail of the program when memory is tight.
What we don't know is why @Best_codes wants to do this, what is his ultimate aim? Because at the moment it is totally useless knowledge.
A bit like asking how you can apply the break and the accelerator at the same time, and accepting the answer, you put one foot on each of the peddles at the same time, is a good answer.
Sure. That should do (although it’s not the run time footprint). You know my point though, so I’ll leave it there.
I want to give a useful answer to @darkmour .
well see post 5 and that thread Irsend Transmitter problem
@darkmour had seen code= irsend.sendNEC(0xF740BF, 32); and I came to believe that he thought he needed to build something (a string) with "0x" in front to pass the value of a variable as first parameter of this irsend.sendNEC() function...
This is typical of a XY problem and so the useful answer was to just do
code= irsend.sendNEC(veri, 32);
and hopefully (OP is MIA so who knows) by now he understands the difference between literal human ASCII representation in a given base versus binary storage in memory...