Anything written in sizeof() is never executed in C

CServer Side ProgrammingProgramming

<p>The sizeof function (Sometimes called operator) is used to calculate the size of the given argument. If some other functions are given as argument, then that will not be executed in the sizeof.</p><p>In the following example we will put one printf() statement inside the loop. Then we will see the output.</p><h2>Example</h2><pre class="prettyprint notranslate">#include&lt;stdio.h&gt; double my_function() { &nbsp; &nbsp;printf(&quot;This is a test function&quot;); &nbsp; &nbsp;return 123456789; } main() { &nbsp; &nbsp;int x; &nbsp; &nbsp;x = sizeof(printf(&quot;Hello World&quot;)); &nbsp; &nbsp;printf(&quot;The size: %d &quot;, x); &nbsp; &nbsp;x = sizeof(my_function()); &nbsp; &nbsp;printf(&quot;The size: %d&quot;, x); }</pre><h2>Output</h2><pre class="result notranslate">The size: 4 The size: 8</pre><p>The printf() is not executed which is present inside the sizeof(). Only the return type is considered, and its size is taken.</p>
raja
Updated on 30-Jul-2019 22:30:26

Advertisements