user48730: For a RF project I need to split payload for a max predefined chunk size.
For that I created a RFmsg struct.
The unexplained part I need help in is why when I create a local instance  of RFmsg, its contents are remain in tact after function is recalled? is it a struct "thing"? or something else I'm missing ?
To solve that I know that wiping struct content after initiating will solve that, but I'm want to be sure.
for that I share a minimal code that:

void newMSG(char *msg) simulates the splitting part of a long msg input.
void printStrcut_content(RFmsg &_payload) prints struct's content.
output show that only after boot, its content are gibberish, but after that, it shows the content of last struct update.

CODE:
#include <Arduino.h>
#define MSG_LEN 10
#define DEVNAME_LEN 8

char *devName = "TEST";

struct RFmsg
{
    int msg_num;
    int tot_msgs;
    int tot_len;
    char payload[MSG_LEN];
    char dev_name[DEVNAME_LEN];
};

void newMSG(char *msg)
{
    RFmsg _payload;
    printStrcut_content(_payload);

    _payload.tot_len = strlen(msg);
    strcpy(_payload.dev_name, devName);
    _payload.tot_msgs = (int)(_payload.tot_len / MSG_LEN);

    if (_payload.tot_len % MSG_LEN > 0)
    {
        _payload.tot_msgs++;
    }

    for (uint8_t i = 0; i < _payload.tot_msgs; i++)
    {
        strcpy(_payload.payload, "");
        for (uint8_t n = 0; n < MSG_LEN; n++)
        {
            _payload.payload[n] = (char)msg[n + i * MSG_LEN];
        }
        _payload.payload[MSG_LEN] = '\0';

        Serial.print("chunk #");
        Serial.print(i);
        Serial.print(": ");
        Serial.println(_payload.payload);
    }
}
void printStrcut_content(RFmsg &_payload)
{
    Serial.print("LEN: ");
    Serial.println(_payload.tot_len);
    Serial.print("PAyLOAD: ");
    Serial.println(_payload.payload);
    Serial.print("name: ");
    Serial.println(_payload.dev_name);
    Serial.print("tot_msgs: ");
    Serial.println(_payload.tot_msgs);
}

void setup()
{
    Serial.begin(115200);
    while (!Serial)
        ;
    Serial.println("\nStart");
}
void loop()
{
    newMSG("1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ");
    delay(5000);
}

OUTPUT:
Start
LEN: 36
PAyLOAD: UVWXYZ
name: 
tot_msgs: 4
chunk #0: 1234567890
chunk #1: ABCDEFGHIJ
chunk #2: KLMNOPQRST
chunk #3: UVWXYZ
LEN: 36
PAyLOAD: UVWXYZ
name: 
tot_msgs: 4
chunk #0: 1234567890
chunk #1: ABCDEFGHIJ
chunk #2: KLMNOPQRST
chunk #3: UVWXYZ
LEN: 36
PAyLOAD: UVWXYZ
name: 
tot_msgs: 4
chunk #0: 1234567890
chunk #1: ABCDEFGHIJ
chunk #2: KLMNOPQRST
chunk #3: UVWXYZ


user42015: As described in the comments: Your local struct variable probably always is placed in the same space in memory and this part of the memory isn't overwritten by your program. When declaring local variables they are not implicitly initialized (written with a value). If you don't initialize the variable yourself, its value will be whatever data is currently in that memory space.
The compiler optimizes your code and also decides on where to place variables on the stack. In this case it is always placed at the same memory space, but you cannot count on that. It is undefined behavior and any change to your program can also change that fact. And you don't have any control over that.
This is the reason, why you should always initialize local variables before reading them.

what do you recommend ?

Just initialize the members of that struct variable before using them. Set all members to a value. You can even do that in one step together with declaring it:
RFmsg _payload = {1, 2, 3, "payload", "devname"};


48730: <p>For a RF project I need to split payload for a max predefined chunk size.
For that I created a <code>RFmsg</code> struct.</p>
<p>The unexplained part I need help in is why when I create a <strong>local</strong> instance  of <code>RFmsg</code>, its contents are remain in tact after function is recalled? is it a struct &quot;thing&quot;? or something else I'm missing ?</p>
<p>To solve that I know that wiping struct content after initiating will solve that, but I'm want to be sure.</p>
<p>for that I share a minimal code that:</p>
<ol>
<li><code>void newMSG(char *msg)</code> simulates the splitting part of a long <code>msg</code> input.</li>
<li><code>void printStrcut_content(RFmsg &amp;_payload)</code> prints struct's content.</li>
<li>output show that only after boot, its content are gibberish, but after that, it shows the <strong>content of last struct update</strong>.</li>
</ol>
<p><em><strong>CODE:</strong></em></p>
<pre><code>#include &lt;Arduino.h&gt;
#define MSG_LEN 10
#define DEVNAME_LEN 8

char *devName = &quot;TEST&quot;;

struct RFmsg
{
    int msg_num;
    int tot_msgs;
    int tot_len;
    char payload[MSG_LEN];
    char dev_name[DEVNAME_LEN];
};

void newMSG(char *msg)
{
    RFmsg _payload;
    printStrcut_content(_payload);

    _payload.tot_len = strlen(msg);
    strcpy(_payload.dev_name, devName);
    _payload.tot_msgs = (int)(_payload.tot_len / MSG_LEN);

    if (_payload.tot_len % MSG_LEN &gt; 0)
    {
        _payload.tot_msgs++;
    }

    for (uint8_t i = 0; i &lt; _payload.tot_msgs; i++)
    {
        strcpy(_payload.payload, &quot;&quot;);
        for (uint8_t n = 0; n &lt; MSG_LEN; n++)
        {
            _payload.payload[n] = (char)msg[n + i * MSG_LEN];
        }
        _payload.payload[MSG_LEN] = '\0';

        Serial.print(&quot;chunk #&quot;);
        Serial.print(i);
        Serial.print(&quot;: &quot;);
        Serial.println(_payload.payload);
    }
}
void printStrcut_content(RFmsg &amp;_payload)
{
    Serial.print(&quot;LEN: &quot;);
    Serial.println(_payload.tot_len);
    Serial.print(&quot;PAyLOAD: &quot;);
    Serial.println(_payload.payload);
    Serial.print(&quot;name: &quot;);
    Serial.println(_payload.dev_name);
    Serial.print(&quot;tot_msgs: &quot;);
    Serial.println(_payload.tot_msgs);
}

void setup()
{
    Serial.begin(115200);
    while (!Serial)
        ;
    Serial.println(&quot;\nStart&quot;);
}
void loop()
{
    newMSG(&quot;1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ&quot;);
    delay(5000);
}
</code></pre>
<p><em><strong>OUTPUT:</strong></em></p>
<pre><code>Start
LEN: 36
PAyLOAD: UVWXYZ
name: 
tot_msgs: 4
chunk #0: 1234567890
chunk #1: ABCDEFGHIJ
chunk #2: KLMNOPQRST
chunk #3: UVWXYZ
LEN: 36
PAyLOAD: UVWXYZ
name: 
tot_msgs: 4
chunk #0: 1234567890
chunk #1: ABCDEFGHIJ
chunk #2: KLMNOPQRST
chunk #3: UVWXYZ
LEN: 36
PAyLOAD: UVWXYZ
name: 
tot_msgs: 4
chunk #0: 1234567890
chunk #1: ABCDEFGHIJ
chunk #2: KLMNOPQRST
chunk #3: UVWXYZ
</code></pre>
 42015: <p>As described in the comments: Your local struct variable probably always is placed in the same space in memory and this part of the memory isn't overwritten by your program. When declaring local variables they are not implicitly initialized (written with a value). If you don't initialize the variable yourself, its value will be whatever data is currently in that memory space.</p>
<p>The compiler optimizes your code and also decides on where to place variables on the stack. In this case it is always placed at the same memory space, but you cannot count on that. It is undefined behavior and any change to your program can also change that fact. And you don't have any control over that.</p>
<p>This is the reason, why you should always initialize local variables before reading them.</p>
<blockquote>
<p>what do you recommend ?</p>
</blockquote>
<p>Just initialize the members of that struct variable before using them. Set all members to a value. You can even do that in one step together with declaring it:</p>
<pre><code>RFmsg _payload = {1, 2, 3, &quot;payload&quot;, &quot;devname&quot;};
</code></pre>
