{"id":8030,"date":"2022-09-11T13:28:36","date_gmt":"2022-09-11T07:58:36","guid":{"rendered":"https:\/\/jassweb.com\/solved\/solved-why-printf-is-not-printing-here\/"},"modified":"2022-09-11T13:28:36","modified_gmt":"2022-09-11T07:58:36","slug":"solved-why-printf-is-not-printing-here","status":"publish","type":"post","link":"https:\/\/jassweb.com\/solved\/solved-why-printf-is-not-printing-here\/","title":{"rendered":"[Solved] why printf is not printing here?"},"content":{"rendered":"<p> [ad_1]<br \/>\n<\/p>\n<div id=\"answer-19464112\" class=\"answer js-answer accepted-answer js-accepted-answer\" data-answerid=\"19464112\" data-parentid=\"19463670\" data-score=\"2\" data-position-on-page=\"3\" data-highest-scored=\"0\" data-question-has-accepted-highest-score=\"0\" itemprop=\"suggestedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n<div class=\"post-layout\">\n<div class=\"votecell post-layout--left\"><\/div>\n<div class=\"answercell post-layout--right\">\n<div class=\"s-prose js-post-body\" itemprop=\"text\">\n<h2>Why here the output is only &#8220;hie&#8221; and &#8220;hola&#8221;?<\/h2>\n<p>Order of precedence of Logical AND (<code>&amp;&amp;<\/code>)  is greater than Logical OR (<code>||<\/code>). Agreed. But, it doesn&#8217;t mean that a program has to evaluate in that order. It just says to group together the expressions. Hence, <\/p>\n<pre><code>if(printf(\"hie\")|| printf(\"hello\")&amp;&amp; printf(\"nice to see you\"))\n<\/code><\/pre>\n<p>is equivalent to, <\/p>\n<pre><code> if(printf(\"hie\")  ||  (printf(\"hello\")&amp;&amp; printf(\"nice to see you\")) )\n<\/code><\/pre>\n<p>Short circuit evaluation of &#8216;<code>||<\/code>&#8216; operator happens:<\/p>\n<blockquote>\n<p>[C11: \u00a76.5.14\/4] Unlike the bitwise | operator, the || operator guarantees left-to-right evaluation; if the second operand is evaluated, there is a sequence point between the evaluations of the first and second operands. <strong>If the first operand compares unequal to 0, the second operand is not evaluated.<\/strong><\/p>\n<\/blockquote>\n<p>So, <code>hie<\/code> gets printed first and returns a <code>non-zero-value<\/code>, satisifies the <code>||<\/code> condition, followed by <code>if<\/code> condition returning <code>true<\/code>.<\/p>\n<hr>\n<h2>More about order of precedence and order of evaluation :<\/h2>\n<p>One of the answers, states that <\/p>\n<blockquote>\n<p>Order of evaluation does not depend on precedence, associativity, or (necessarily) on apparent dependencies. <\/p>\n<\/blockquote>\n<p>Though this is closer but this is not completely true. Though precedence is not the same thing as <em>order of evaluation<\/em>. There are cases wherein the precedence <em>indirectly<\/em> influences the order of evaluation. <\/p>\n<p>Consider, <\/p>\n<blockquote>\n<p>1 + 2 * 3<\/p>\n<\/blockquote>\n<p>It is obvious that, order of precedence of <code>*<\/code> is higher than <code>+<\/code>. When two operators share an operand, precedence dives into picture, and the operand is grouped with the operator with the highest precedence. In the above statement <code>*<\/code> and <code>+<\/code> share the same operand <code>2<\/code>, precedence tells that multiplication operator is applied to <code>2<\/code> and <code>3<\/code>. <code>+<\/code> is applied to <code>1<\/code> and the result of multiplication. So, compiler parses the above statement as,<\/p>\n<blockquote>\n<p>1 + (2 *3)<\/p>\n<\/blockquote>\n<p>The constraint on the order of evaluation of above expression is that, addition can&#8217;t be completed without the result of multiplication. So, in this case, multiplication(higher precedence) is evaluated before addition(lower precedence)<\/p>\n<hr>\n<p>In your <code>if()<\/code> statement, precedence tells to compiler to parse the statement in such a way that it has an implicit paranthesis enclosing 2nd and 3rd <code>printf()<\/code>. That doesn&#8217;t mean those has to be evaluated first as explained earlier.<\/p>\n<p>So, we have seen two cases. In one, precedence doesn&#8217;t control\/influence order of evaluation and in other precedence had an indirect influence.<\/p>\n<p>__<\/p>\n<h2>In short<\/h2>\n<p>&#8220;While precedence may <em>influence<\/em> the order of evaluation, it doesn&#8217;t <em>determine<\/em> the order of evaluation&#8221;<\/p>\n<\/p><\/div>\n<div class=\"mt24\"><\/div>\n<\/div>\n<p>            <span class=\"d-none\" itemprop=\"commentCount\">6<\/span> <\/p><\/div>\n<\/div>\n<p>[ad_2]<\/p>\n<p>solved why printf is not printing here? <\/p>\n","protected":false},"excerpt":{"rendered":"<p>[ad_1] Why here the output is only &#8220;hie&#8221; and &#8220;hola&#8221;? Order of precedence of Logical AND (&amp;&amp;) is greater than Logical OR (||). Agreed. But, it doesn&#8217;t mean that a program has to evaluate in that order. It just says to group together the expressions. Hence, if(printf(&#8220;hie&#8221;)|| printf(&#8220;hello&#8221;)&amp;&amp; printf(&#8220;nice to see you&#8221;)) is equivalent to, &#8230; <a title=\"[Solved] why printf is not printing here?\" class=\"read-more\" href=\"https:\/\/jassweb.com\/solved\/solved-why-printf-is-not-printing-here\/\" aria-label=\"More on [Solved] why printf is not printing here?\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[320],"tags":[324,584],"class_list":["post-8030","post","type-post","status-publish","format-standard","hentry","category-solved","tag-c","tag-printf"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>[Solved] why printf is not printing here? - JassWeb<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jassweb.com\/solved\/solved-why-printf-is-not-printing-here\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[Solved] why printf is not printing here? - JassWeb\" \/>\n<meta property=\"og:description\" content=\"[ad_1] Why here the output is only &#8220;hie&#8221; and &#8220;hola&#8221;? Order of precedence of Logical AND (&amp;&amp;) is greater than Logical OR (||). Agreed. But, it doesn&#8217;t mean that a program has to evaluate in that order. It just says to group together the expressions. Hence, if(printf(&quot;hie&quot;)|| printf(&quot;hello&quot;)&amp;&amp; printf(&quot;nice to see you&quot;)) is equivalent to, ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jassweb.com\/solved\/solved-why-printf-is-not-printing-here\/\" \/>\n<meta property=\"og:site_name\" content=\"JassWeb\" \/>\n<meta property=\"article:published_time\" content=\"2022-09-11T07:58:36+00:00\" \/>\n<meta name=\"author\" content=\"Kirat\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kirat\" \/>\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\":\"Article\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-why-printf-is-not-printing-here\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-why-printf-is-not-printing-here\/\"},\"author\":{\"name\":\"Kirat\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\"},\"headline\":\"[Solved] why printf is not printing here?\",\"datePublished\":\"2022-09-11T07:58:36+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-why-printf-is-not-printing-here\/\"},\"wordCount\":370,\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"keywords\":[\"c++\",\"printf\"],\"articleSection\":[\"Solved\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-why-printf-is-not-printing-here\/\",\"url\":\"https:\/\/jassweb.com\/solved\/solved-why-printf-is-not-printing-here\/\",\"name\":\"[Solved] why printf is not printing here? - JassWeb\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#website\"},\"datePublished\":\"2022-09-11T07:58:36+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-why-printf-is-not-printing-here\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/jassweb.com\/solved\/solved-why-printf-is-not-printing-here\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-why-printf-is-not-printing-here\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/jassweb.com\/solved\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[Solved] why printf is not printing here?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/jassweb.com\/solved\/#website\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"name\":\"JassWeb\",\"description\":\"Build High-quality Websites\",\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/jassweb.com\/solved\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\",\"name\":\"Jass Web\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"contentUrl\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"width\":693,\"height\":132,\"caption\":\"Jass Web\"},\"image\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\",\"name\":\"Kirat\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750\",\"contentUrl\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750\",\"caption\":\"Kirat\"},\"sameAs\":[\"http:\/\/jassweb.com\"],\"url\":\"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[Solved] why printf is not printing here? - JassWeb","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:\/\/jassweb.com\/solved\/solved-why-printf-is-not-printing-here\/","og_locale":"en_US","og_type":"article","og_title":"[Solved] why printf is not printing here? - JassWeb","og_description":"[ad_1] Why here the output is only &#8220;hie&#8221; and &#8220;hola&#8221;? Order of precedence of Logical AND (&amp;&amp;) is greater than Logical OR (||). Agreed. But, it doesn&#8217;t mean that a program has to evaluate in that order. It just says to group together the expressions. Hence, if(printf(\"hie\")|| printf(\"hello\")&amp;&amp; printf(\"nice to see you\")) is equivalent to, ... Read more","og_url":"https:\/\/jassweb.com\/solved\/solved-why-printf-is-not-printing-here\/","og_site_name":"JassWeb","article_published_time":"2022-09-11T07:58:36+00:00","author":"Kirat","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kirat","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jassweb.com\/solved\/solved-why-printf-is-not-printing-here\/#article","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/solved-why-printf-is-not-printing-here\/"},"author":{"name":"Kirat","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31"},"headline":"[Solved] why printf is not printing here?","datePublished":"2022-09-11T07:58:36+00:00","mainEntityOfPage":{"@id":"https:\/\/jassweb.com\/solved\/solved-why-printf-is-not-printing-here\/"},"wordCount":370,"publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"keywords":["c++","printf"],"articleSection":["Solved"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/jassweb.com\/solved\/solved-why-printf-is-not-printing-here\/","url":"https:\/\/jassweb.com\/solved\/solved-why-printf-is-not-printing-here\/","name":"[Solved] why printf is not printing here? - JassWeb","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/#website"},"datePublished":"2022-09-11T07:58:36+00:00","breadcrumb":{"@id":"https:\/\/jassweb.com\/solved\/solved-why-printf-is-not-printing-here\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jassweb.com\/solved\/solved-why-printf-is-not-printing-here\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jassweb.com\/solved\/solved-why-printf-is-not-printing-here\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/jassweb.com\/solved\/"},{"@type":"ListItem","position":2,"name":"[Solved] why printf is not printing here?"}]},{"@type":"WebSite","@id":"https:\/\/jassweb.com\/solved\/#website","url":"https:\/\/jassweb.com\/solved\/","name":"JassWeb","description":"Build High-quality Websites","publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jassweb.com\/solved\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/jassweb.com\/solved\/#organization","name":"Jass Web","url":"https:\/\/jassweb.com\/solved\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/","url":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","contentUrl":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","width":693,"height":132,"caption":"Jass Web"},"image":{"@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31","name":"Kirat","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/","url":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750","contentUrl":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750","caption":"Kirat"},"sameAs":["http:\/\/jassweb.com"],"url":"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/"}]}},"_links":{"self":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/8030","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/comments?post=8030"}],"version-history":[{"count":0,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/8030\/revisions"}],"wp:attachment":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/media?parent=8030"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/categories?post=8030"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/tags?post=8030"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}