snipt

Ctrl+h for KB shortcuts

C

Struct initializer

1
2
3
  struct s {int x[30]; int y; } y = {{1,2} ,3};
  printf("%d %d\n", y.x[1], y.y);
  // 2 3
https://snipt.net/embed/7d8b026a50c93db22bec417aae169d86/
/raw/7d8b026a50c93db22bec417aae169d86/
7d8b026a50c93db22bec417aae169d86
c
C
3
2019-06-23T08:35:32
True
False
False
/api/public/snipt/7401/
struct-initializer
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a> <span class="k">struct</span> <span class="n">s</span> <span class="p">{</span><span class="kt">int</span> <span class="n">x</span><span class="p">[</span><span class="mi">30</span><span class="p">];</span> <span class="kt">int</span> <span class="n">y</span><span class="p">;</span> <span class="p">}</span> <span class="n">y</span> <span class="o">=</span> <span class="p">{{</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">}</span> <span class="p">,</span><span class="mi">3</span><span class="p">};</span> </span><span id="L-2"><a name="L-2"></a> <span class="n">printf</span><span class="p">(</span><span class="s">&quot;%d %d</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">y</span><span class="p">.</span><span class="n">x</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">y</span><span class="p">.</span><span class="n">y</span><span class="p">);</span> </span><span id="L-3"><a name="L-3"></a> <span class="c1">// 2 3</span> </span></pre></div> </td></tr></table>
c, initialize, struct