segmentation fault for the code
<pre><code>#include&lt;iostream&gt;
#include&lt;stdlib.h&gt;
#include&lt;string.h&gt;
#include&lt;stdio.h&gt;

using namespace std;

union type{
            int a;
            char b;
            int *p;
            char *s;
            int arr[10];
};

int fn(union type *exp){

    exp-&gt;p = exp-&gt;p+1;
    cout &lt;&lt; *(exp-&gt;p);
    cout &lt;&lt; "\n";
return 0;
}

int main(){

    union type *str;
    str-&gt;a = 10;
    str-&gt;b = 'n';
    str-&gt;p = &amp;(str-&gt;a);
    cout &lt;&lt; (str-&gt;p);
    cout &lt;&lt; "\n";
    fn(str);
    cout &lt;&lt; str-&gt;p;
    cout &lt;&lt; "\n";
return 0;
}
</code></pre>

<p>This code is giving me segmentation fault. Is it because i need to allocate memory to the union explicitly using malloc?? I am new to coding and trying to learn c++. </p>
