<br />
<b>Warning</b>:  Undefined array key "global_protection_id" in <b>/home/wikitechy/public_html/interview-questions/wp-content/plugins/content-protector/inc/class-ps-rest-handler.php</b> on line <b>51</b><br />
{"id":4790,"date":"2022-08-19T07:40:38","date_gmt":"2022-08-19T07:40:38","guid":{"rendered":"https:\/\/www.wikitechy.com\/interview-questions\/?p=4790"},"modified":"2022-08-19T07:40:38","modified_gmt":"2022-08-19T07:40:38","slug":"what-is-bool-data-in-c","status":"publish","type":"post","link":"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-bool-data-in-c\/","title":{"rendered":"What is bool data in C++ ?"},"content":{"rendered":"<ul>\n<li style=\"text-align: justify;\">In C++ Boolean data type is defined using the bool keyword.<\/li>\n<li style=\"text-align: justify;\">This servers as an easy and convenient datatype for programmers to manage and write conditional statements using a boolean value, rather than an int.<\/li>\n<li style=\"text-align: justify;\">Usually true or false are assigned to boolean variables as their default numerical values.<\/li>\n<li style=\"text-align: justify;\">In C++ any numerical value can be assigned to a boolean variable, all values other than\u00a000\u00a0are considered to be\u00a0true and stored as\u00a01, while\u00a00\u00a0is considered to be\u00a0false.<\/li>\n<li style=\"text-align: justify;\">In certain situations, they are provided to provide better control as well as for providing conveniences to C++ programmers.<\/li>\n<li style=\"text-align: justify;\">At C++ language the values\u00a0<em>true<\/em><em>\u00a0<\/em>or\u00a0<em>false<\/em>\u00a0have been added as keywords.<\/li>\n<li style=\"text-align: justify;\">We can use bool type values or variables true and false in mathematical expressions.<\/li>\n<\/ul>\n<p><img fetchpriority=\"high\" decoding=\"async\" class=\"alignnone size-full wp-image-4791 aligncenter\" src=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/boolean-type.png\" alt=\"\" width=\"1219\" height=\"548\" srcset=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/boolean-type.png 1219w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/boolean-type-300x135.png 300w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/boolean-type-1024x460.png 1024w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/boolean-type-768x345.png 768w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/boolean-type-390x175.png 390w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/boolean-type-820x369.png 820w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/boolean-type-1180x530.png 1180w\" sizes=\"(max-width: 1219px) 100vw, 1219px\" \/><\/p>\n<ul>\n<li>In numerical expression a boolean variable in C++ can be used as well.<\/li>\n<li>if a\u00a0bool variable is equal to\u00a0true (or any numeric value other than\u00a00),\u00a01is assigned to it and taken as\u00a01\u00a0during the evaluation of the expression;\u00a00 and\u00a0false will be taken as\u00a00.<\/li>\n<\/ul>\n<h2 id=\"sample-code\">Sample Code<\/h2>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-cpp code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-cpp code-embed-code\">#include &lt;iostream&gt;<br\/>using namespace std;<br\/><br\/>int main() {<br\/>  bool x = 10;  \/\/ x = 1;<br\/>  bool y = false;  \/\/ y = 0;<br\/><br\/>  \/\/ Using bool in a numeric expression:<br\/>  cout &lt;&lt; 2 * (x + y) &lt;&lt; endl;<br\/>  <br\/>  return 0;<br\/>}<\/code><\/pre> <\/div>\n<h2 id=\"output\">Output<\/h2>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-4792\" src=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/boolean-data.png\" alt=\"\" width=\"1150\" height=\"168\" srcset=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/boolean-data.png 1150w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/boolean-data-300x44.png 300w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/boolean-data-1024x150.png 1024w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/boolean-data-768x112.png 768w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/boolean-data-390x57.png 390w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/boolean-data-820x120.png 820w\" sizes=\"(max-width: 1150px) 100vw, 1150px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In C++ Boolean data type is defined using the bool keyword. This servers as an easy and convenient datatype for programmers to manage and write conditional statements using a boolean value, rather than an int. Usually true or false are assigned to boolean variables as their default numerical values. In C++ any numerical value can [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"passster_activate_protection":false,"passster_protect_child_pages":"","passster_protection_type":"password","passster_password":"","passster_activate_overwrite_defaults":"","passster_headline":"","passster_instruction":"","passster_placeholder":"","passster_button":"","passster_id":"","passster_activate_misc_settings":"","passster_redirect_url":"","passster_hide":"no","passster_area_shortcode":"","gtb_hide_title":false,"gtb_wrap_title":false,"gtb_class_title":"","gtb_remove_headerfooter":false,"footnotes":""},"categories":[2080],"tags":[18401,18402,18403,18398,18397,18400,18396,18404,18395,18399],"class_list":["post-4790","post","type-post","status-publish","format-standard","hentry","category-cpp","tag-bool-data-type-in-c","tag-boolean-array-in-c","tag-boolean-in-c","tag-boolean-in-c-with-example","tag-c-boolean","tag-c-boolean-data-types","tag-use-of-bool-in-c","tag-what-is-bool-data-type-in-c","tag-what-is-boolean-in-c","tag-working-with-boolean-in-c"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>What is bool data in C++ - C++ Boolean Data Type - bool data type in c++<\/title>\n<meta name=\"description\" content=\"What is bool data in C++ - In C++ Boolean data type is defined using the bool keyword. This servers as an easy and convenient datatype for programmers to manage and write conditional statements using a boolean value, rather than an int.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-bool-data-in-c\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"What is bool data in C++ - C++ Boolean Data Type - bool data type in c++\" \/>\n<meta property=\"og:description\" content=\"What is bool data in C++ - In C++ Boolean data type is defined using the bool keyword. This servers as an easy and convenient datatype for programmers to manage and write conditional statements using a boolean value, rather than an int.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-bool-data-in-c\/\" \/>\n<meta property=\"og:site_name\" content=\"Wikitechy\" \/>\n<meta property=\"article:published_time\" content=\"2022-08-19T07:40:38+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/boolean-type.png\" \/>\n<meta name=\"author\" content=\"webmaster\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"webmaster\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-bool-data-in-c\/\",\"url\":\"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-bool-data-in-c\/\",\"name\":\"What is bool data in C++ - C++ Boolean Data Type - bool data type in c++\",\"isPartOf\":{\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-bool-data-in-c\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-bool-data-in-c\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/boolean-type.png\",\"datePublished\":\"2022-08-19T07:40:38+00:00\",\"dateModified\":\"2022-08-19T07:40:38+00:00\",\"author\":{\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/f785ba3ecc599133e65ab6138042a3e4\"},\"description\":\"What is bool data in C++ - In C++ Boolean data type is defined using the bool keyword. This servers as an easy and convenient datatype for programmers to manage and write conditional statements using a boolean value, rather than an int.\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-bool-data-in-c\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-bool-data-in-c\/#primaryimage\",\"url\":\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/boolean-type.png\",\"contentUrl\":\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/boolean-type.png\",\"width\":1219,\"height\":548},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#website\",\"url\":\"https:\/\/www.wikitechy.com\/interview-questions\/\",\"name\":\"Wikitechy\",\"description\":\"Interview Questions\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wikitechy.com\/interview-questions\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/f785ba3ecc599133e65ab6138042a3e4\",\"name\":\"webmaster\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/155b77fd8cdda3d0913fcb7e7ee63543b0c345d2d8f6dcebda5b0583ab61f967?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/155b77fd8cdda3d0913fcb7e7ee63543b0c345d2d8f6dcebda5b0583ab61f967?s=96&d=mm&r=g\",\"caption\":\"webmaster\"},\"sameAs\":[\"https:\/\/www.wikitechy.com\/interview-questions\"],\"url\":\"https:\/\/www.wikitechy.com\/interview-questions\/author\/webmaster\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"What is bool data in C++ - C++ Boolean Data Type - bool data type in c++","description":"What is bool data in C++ - In C++ Boolean data type is defined using the bool keyword. This servers as an easy and convenient datatype for programmers to manage and write conditional statements using a boolean value, rather than an int.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-bool-data-in-c\/","og_locale":"en_US","og_type":"article","og_title":"What is bool data in C++ - C++ Boolean Data Type - bool data type in c++","og_description":"What is bool data in C++ - In C++ Boolean data type is defined using the bool keyword. This servers as an easy and convenient datatype for programmers to manage and write conditional statements using a boolean value, rather than an int.","og_url":"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-bool-data-in-c\/","og_site_name":"Wikitechy","article_published_time":"2022-08-19T07:40:38+00:00","og_image":[{"url":"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/boolean-type.png"}],"author":"webmaster","twitter_card":"summary_large_image","twitter_misc":{"Written by":"webmaster","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-bool-data-in-c\/","url":"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-bool-data-in-c\/","name":"What is bool data in C++ - C++ Boolean Data Type - bool data type in c++","isPartOf":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-bool-data-in-c\/#primaryimage"},"image":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-bool-data-in-c\/#primaryimage"},"thumbnailUrl":"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/boolean-type.png","datePublished":"2022-08-19T07:40:38+00:00","dateModified":"2022-08-19T07:40:38+00:00","author":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/f785ba3ecc599133e65ab6138042a3e4"},"description":"What is bool data in C++ - In C++ Boolean data type is defined using the bool keyword. This servers as an easy and convenient datatype for programmers to manage and write conditional statements using a boolean value, rather than an int.","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-bool-data-in-c\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-bool-data-in-c\/#primaryimage","url":"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/boolean-type.png","contentUrl":"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/boolean-type.png","width":1219,"height":548},{"@type":"WebSite","@id":"https:\/\/www.wikitechy.com\/interview-questions\/#website","url":"https:\/\/www.wikitechy.com\/interview-questions\/","name":"Wikitechy","description":"Interview Questions","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wikitechy.com\/interview-questions\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/f785ba3ecc599133e65ab6138042a3e4","name":"webmaster","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/155b77fd8cdda3d0913fcb7e7ee63543b0c345d2d8f6dcebda5b0583ab61f967?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/155b77fd8cdda3d0913fcb7e7ee63543b0c345d2d8f6dcebda5b0583ab61f967?s=96&d=mm&r=g","caption":"webmaster"},"sameAs":["https:\/\/www.wikitechy.com\/interview-questions"],"url":"https:\/\/www.wikitechy.com\/interview-questions\/author\/webmaster\/"}]}},"_links":{"self":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/4790","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/comments?post=4790"}],"version-history":[{"count":1,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/4790\/revisions"}],"predecessor-version":[{"id":4793,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/4790\/revisions\/4793"}],"wp:attachment":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/media?parent=4790"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/categories?post=4790"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/tags?post=4790"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}