{"id":501,"date":"2019-05-04T17:59:46","date_gmt":"2019-05-04T17:59:46","guid":{"rendered":"http:\/\/kabiliravi.com\/?page_id=501"},"modified":"2019-07-21T13:47:54","modified_gmt":"2019-07-21T13:47:54","slug":"primitive-data-types","status":"publish","type":"page","link":"http:\/\/kabiliravi.com\/index.php\/software\/programming\/mycpptutorial\/basic-syntax\/primitive-data-types\/","title":{"rendered":"Primitive Data Types"},"content":{"rendered":"\n<p>Primitive types are the basic data types serve as the building blocks of data manipulation in any programming language including Java.<\/p>\n\n\n\n<p>In a programming language, a variable has a type such as Integer, String, Decimal, &#8230; whether that programming language is a <strong><a href=\"http:\/\/wiki.c2.com\/?StaticTyping\">Static Typing<\/a><\/strong> such as C\/C++ and Java or <strong><a href=\"http:\/\/wiki.c2.com\/?DynamicTyping\">Dynamic Typing<\/a><\/strong> like PHP, javascript and Python. <\/p>\n\n\n\n<p>In C++ like other programming languages we have built-in primitive data types. A primitive date type is a <em>basic data type<\/em> provided by a programming language as a basic building block. <br>Here is the list of primitive date types in C++:<\/p>\n\n\n\n<table class=\"wp-block-table alignwide\"><tbody><tr><td><strong>Group<\/strong><\/td><td><strong>Keyword<\/strong><\/td><td><strong>Size <\/strong><\/td><\/tr><tr><td>Boolean Types<\/td><td><strong>bool<\/strong><\/td><td>8 bits<\/td><\/tr><tr><td>Character Types<\/td><td><strong>char<\/strong><\/td><td>8 bits<\/td><\/tr><tr><td>Character Types<\/td><td><strong>char16_t<\/strong><\/td><td>16 bits<\/td><\/tr><tr><td>Character Types<\/td><td><strong>char32_t<\/strong><\/td><td>32 bits<\/td><\/tr><tr><td>Character Types<\/td><td><strong>wchar_t<\/strong><\/td><td><strong>gt<\/strong> 16 bits and <strong>lt<\/strong> 32 bits<\/td><\/tr><tr><td>Integer Types<\/td><td><strong>char<\/strong><\/td><td>8 bits<\/td><\/tr><tr><td>Integer Types<\/td><td><strong>int<\/strong><\/td><td><strong>gt<\/strong> 16 bits and <strong>lt<\/strong> 32 bits<\/td><\/tr><tr><td>Integer Types<\/td><td><strong>short<\/strong><\/td><td>16 bits<\/td><\/tr><tr><td>Integer Types<\/td><td><strong>long<\/strong><\/td><td>32 bits<\/td><\/tr><tr><td>Integer Types<\/td><td><strong>long long<\/strong><\/td><td>64 bits<\/td><\/tr><tr><td>Floating-point Types<\/td><td><strong>float<\/strong><\/td><td>32 bits<\/td><\/tr><tr><td>Floating-point Types<\/td><td><strong>double<\/strong><\/td><td><strong>gt<\/strong> 32 bits and <strong>lt<\/strong> 64 bits<\/td><\/tr><tr><td>Floating-point Types<\/td><td><strong>long double<\/strong><\/td><td>64 bits, lt <strong>double<\/strong><\/td><\/tr><tr><td>Void Type<\/td><td><strong>void<\/strong><\/td><td>no storage<\/td><\/tr><\/tbody><\/table>\n\n\n\n<p>I created couple of samples in <br><a href=\"https:\/\/github.com\/mycpptutorial\/primitive-data-types.git\">https:\/\/github.com\/mycpptutorial\/primitive-data-types.git<\/a> to play with each type.<\/p>\n\n\n\n<p>In the first sample in <strong>trybool.cpp<\/strong>, you will learn how to define a boolean variable and how to set its value:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\/** <strong>trybool.cpp<\/strong>**\/<br>#include &lt;iostream&gt;<br><br>int main (void){<br>  bool try_me = false;<br><br>  std::cout &lt;&lt; \"try_me value: \";<br>  std::cout &lt;&lt; try_me;<br>  std::cout &lt;&lt; \"\\n\";<br><br>  try_me = true;<br>  std::cout &lt;&lt; \"try_me value: \";<br>  std::cout &lt;&lt; try_me;<br>  std::cout &lt;&lt; \"\\n\";<br><br>  std::cout &lt;&lt; \"The size of try_me is \";<br>  std::cout &lt;&lt; sizeof try_me;<br>  std::cout &lt;&lt; \" byte(s)\\n\";<br>}<\/pre>\n\n\n\n<p>You start all C++ executable application with a starter function called<strong> main()<\/strong>. Refer to <a href=\"http:\/\/kabiliravi.com\/index.php\/software\/programming\/mycpptutorial\/environment-setup\/build-and-run-your-first-application-with-gcc\/\">Build You First Application<\/a> to have more information about it. As you see in the above sample, in the first line of main() function block, I defined a boolean variable simply by have <strong>bool<\/strong> type at the beginning of the line, then the variable name <strong>try_me<\/strong> right after that with a space character and assigned its value immediately on its declaration (definition) line with &#8220;<strong>= false<\/strong>&#8220;. Notice that all lines are ended by <strong>; (semicolon)<\/strong> character.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">bool try_me = false;<\/pre>\n\n\n\n<p>Next, I have the text <strong>&#8220;The size of try_me is &#8220;<\/strong> printed with a <strong>cout<\/strong> function and belongs to <strong>std<\/strong> namesapce as <strong>std::cout<\/strong>.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">std::cout &lt;&lt; \"try_me value: \";<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Primitive types are the basic data types serve as the building blocks of data manipulation in any programming language including Java. In a programming language, a variable has a type such as Integer, String, Decimal, &#8230; whether that programming language is a Static Typing such as C\/C++ and Java or Dynamic Typing like PHP, javascript [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":499,"menu_order":0,"comment_status":"open","ping_status":"closed","template":"","meta":{"ngg_post_thumbnail":0,"footnotes":""},"class_list":["post-501","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"http:\/\/kabiliravi.com\/index.php\/wp-json\/wp\/v2\/pages\/501","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/kabiliravi.com\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"http:\/\/kabiliravi.com\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"http:\/\/kabiliravi.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/kabiliravi.com\/index.php\/wp-json\/wp\/v2\/comments?post=501"}],"version-history":[{"count":40,"href":"http:\/\/kabiliravi.com\/index.php\/wp-json\/wp\/v2\/pages\/501\/revisions"}],"predecessor-version":[{"id":997,"href":"http:\/\/kabiliravi.com\/index.php\/wp-json\/wp\/v2\/pages\/501\/revisions\/997"}],"up":[{"embeddable":true,"href":"http:\/\/kabiliravi.com\/index.php\/wp-json\/wp\/v2\/pages\/499"}],"wp:attachment":[{"href":"http:\/\/kabiliravi.com\/index.php\/wp-json\/wp\/v2\/media?parent=501"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}