title: Size of character ('a') in C/C++
body: <p>What is the size of character in C and C++ ? As far as I know the size of char is 1 byte in both C and C++.</p>
  
  <p><strong><a href="https://web.archive.org/web/20000000000000/http://www.ideone.com/e3Yo1Kyf" rel="noreferrer">In C:</a></strong></p>
  
  <pre><code>#include &lt;stdio.h&gt;
  int main()
  {
      printf("Size of char : %d\n", sizeof(char));
      return 0;
  }
  </code></pre>
  
  <p><strong><a href="https://web.archive.org/web/20000000000000/http://www.ideone.com/uG4Qodfo" rel="noreferrer">In C++:</a></strong></p>
  
  <pre><code>#include &lt;iostream&gt;
  int main()
  {
      std::cout &lt;&lt; "Size of char : " &lt;&lt; sizeof(char) &lt;&lt; "\n";
      return 0;
  }
  </code></pre>
  
  <p>No surprises, both of them gives the output : <code>Size of char : 1</code></p>
  
  <p>Now we know that characters are represented as <code>'a'</code>,<code>'b'</code>,<code>'c'</code>,<code>'|'</code>,... So I just modified the above codes to these:</p>
  
  <p><strong>In C:</strong></p>
  
  <pre><code>#include &lt;stdio.h&gt;
  int main()
  {
      char a = 'a';
      printf("Size of char : %d\n", sizeof(a));
      printf("Size of char : %d\n", sizeof('a'));
      return 0;
  }
  </code></pre>
  
  <p><strong><a href="https://web.archive.org/web/20000000000000/http://www.ideone.com/Y11gm1lw" rel="noreferrer">Output:</a></strong></p>
  
  <pre><code>Size of char : 1
  Size of char : 4
  </code></pre>
  
  <p><strong>In C++:</strong></p>
  
  <pre><code>#include &lt;iostream&gt;
  int main()
  {
      char a = 'a';
      std::cout &lt;&lt; "Size of char : " &lt;&lt; sizeof(a) &lt;&lt; "\n";
      std::cout &lt;&lt; "Size of char : " &lt;&lt; sizeof('a') &lt;&lt; "\n";
      return 0;
  }
  </code></pre>
  
  <p><strong><a href="https://web.archive.org/web/20000000000000/http://www.ideone.com/b00pdptc" rel="noreferrer">Output:</a></strong></p>
  
  <pre><code>Size of char : 1
  Size of char : 1
  </code></pre>
  
  <p><strong>Why the <code>sizeof('a')</code> returns different values in C and C++?</strong></p>