<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":4911,"date":"2022-10-03T06:56:02","date_gmt":"2022-10-03T06:56:02","guid":{"rendered":"https:\/\/www.wikitechy.com\/interview-questions\/?p=4911"},"modified":"2022-10-03T07:00:53","modified_gmt":"2022-10-03T07:00:53","slug":"what-is-switch-statement-in-c-with-example","status":"publish","type":"post","link":"https:\/\/www.wikitechy.com\/interview-questions\/c\/what-is-switch-statement-in-c-with-example\/","title":{"rendered":"What is Switch Statement in C with example ?"},"content":{"rendered":"<ul style=\"text-align: justify;\">\n<li style=\"text-align: justify;\">Switch statement is an alternative to if else ladder statement which allows us to execute multiple operations for different values.<\/li>\n<li>We can define various statement in multiple cases for different values of single variable.<\/li>\n<\/ul>\n<h2 id=\"rules-for-switch-statement\" style=\"text-align: justify;\">Rules for switch statement<\/h2>\n<ul style=\"text-align: justify;\">\n<li>Switch expression should be an integer or character data type.<\/li>\n<li>Case value must be an integer or constant value.<\/li>\n<li>We can use only case value inside the switch statement.<\/li>\n<li>Break statement is not mandatory in switch. It is optional.<\/li>\n<li>If a program does not find a break statement in switch expression, all the cases in the switch will be executed along with the matched case.<\/li>\n<\/ul>\n<h2 id=\"syntax-for-switch-statement\" style=\"text-align: justify;\">Syntax for switch statement<\/h2>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-c code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-c code-embed-code\">switch(expression){    <br\/>case value1:    <br\/>\/\/code to be executed;    <br\/>break;  \/\/optional  <br\/>case value2:    <br\/>\/\/code to be executed;    <br\/>break;  \/\/optional  <br\/>......    <br\/>default:     <br\/>code to be executed if all cases are not matched;    <br\/>}    <\/code><\/pre> <\/div>\n<h2 id=\"flow-chart-for-switch\">Flow chart for switch<\/h2>\n<p><img fetchpriority=\"high\" decoding=\"async\" class=\"alignnone size-full wp-image-4913 aligncenter\" src=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/10\/switch-statement-in-c.png\" alt=\"\" width=\"730\" height=\"590\" srcset=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/10\/switch-statement-in-c.png 730w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/10\/switch-statement-in-c-300x242.png 300w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/10\/switch-statement-in-c-390x315.png 390w\" sizes=\"(max-width: 730px) 100vw, 730px\" \/><\/p>\n<h2 id=\"sample-program\">Sample Program<\/h2>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-c code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-c code-embed-code\">    #include&lt;stdio.h&gt;<br\/><br\/>    int main() {<br\/>      int number = 0;<br\/>      printf(&quot;enter a number:&quot;);<br\/>      scanf(&quot;%d&quot;, &amp; number);<br\/>      switch (number) {<br\/>      case 10:<br\/>        printf(&quot;number is equals to 10&quot;);<br\/>        break;<br\/>      case 50:<br\/>        printf(&quot;number is equal to 50&quot;);<br\/>        break;<br\/>      case 100:<br\/>        printf(&quot;number is equal to 100&quot;);<br\/>        break;<br\/>      default:<br\/>        printf(&quot;number is not equal to 10, 50 or 100&quot;);<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-4916 aligncenter\" src=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/10\/switch-case-examples.jpg\" alt=\"\" width=\"329\" height=\"182\" srcset=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/10\/switch-case-examples.jpg 329w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/10\/switch-case-examples-300x166.jpg 300w\" sizes=\"(max-width: 329px) 100vw, 329px\" \/><\/p>\n<p style=\"text-align: justify;\">\n","protected":false},"excerpt":{"rendered":"<p>Switch statement is an alternative to if else ladder statement which allows us to execute multiple operations for different values. We can define various statement in multiple cases for different values of single variable. Rules for switch statement Switch expression should be an integer or character data type. Case value must be an integer or [&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":[1716],"tags":[18746,18751,2039,18748,2031,2032,2034,18749,18747,18752,18753,18755,18750,18756,18754],"class_list":["post-4911","post","type-post","status-publish","format-standard","hentry","category-c","tag-c-switch-statement","tag-example-of-switch-statement","tag-switch-case-example-in-c","tag-switch-case-in-c","tag-switch-case-in-c-programming-examples","tag-switch-case-in-c-programming-questions","tag-switch-statement-in-c","tag-switch-statement-with-examples","tag-switch-case-in-c-programming","tag-syntax-of-switch-statement","tag-what-is-switch-in-c-language","tag-what-is-switch-in-c-programming","tag-what-is-switch-statement-in-c","tag-what-is-switch-statement-in-c-programming","tag-what-is-switch-statement-in-c-with-example"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>What is Switch Statement in C with example ? - Switch Case in C<\/title>\n<meta name=\"description\" content=\"What is Switch Statement in C with example ? - Switch statement is an alternative to if else ladder statement which allows us to execute multiple operations for different values.\" \/>\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\/c\/what-is-switch-statement-in-c-with-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"What is Switch Statement in C with example ? - Switch Case in C\" \/>\n<meta property=\"og:description\" content=\"What is Switch Statement in C with example ? - Switch statement is an alternative to if else ladder statement which allows us to execute multiple operations for different values.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wikitechy.com\/interview-questions\/c\/what-is-switch-statement-in-c-with-example\/\" \/>\n<meta property=\"og:site_name\" content=\"Wikitechy\" \/>\n<meta property=\"article:published_time\" content=\"2022-10-03T06:56:02+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-10-03T07:00:53+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/10\/switch-statement-in-c.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=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/c\/what-is-switch-statement-in-c-with-example\/\",\"url\":\"https:\/\/www.wikitechy.com\/interview-questions\/c\/what-is-switch-statement-in-c-with-example\/\",\"name\":\"What is Switch Statement in C with example ? - Switch Case in C\",\"isPartOf\":{\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/c\/what-is-switch-statement-in-c-with-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/c\/what-is-switch-statement-in-c-with-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/10\/switch-statement-in-c.png\",\"datePublished\":\"2022-10-03T06:56:02+00:00\",\"dateModified\":\"2022-10-03T07:00:53+00:00\",\"author\":{\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/f785ba3ecc599133e65ab6138042a3e4\"},\"description\":\"What is Switch Statement in C with example ? - Switch statement is an alternative to if else ladder statement which allows us to execute multiple operations for different values.\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wikitechy.com\/interview-questions\/c\/what-is-switch-statement-in-c-with-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/c\/what-is-switch-statement-in-c-with-example\/#primaryimage\",\"url\":\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/10\/switch-statement-in-c.png\",\"contentUrl\":\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/10\/switch-statement-in-c.png\",\"width\":730,\"height\":590},{\"@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 Switch Statement in C with example ? - Switch Case in C","description":"What is Switch Statement in C with example ? - Switch statement is an alternative to if else ladder statement which allows us to execute multiple operations for different values.","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\/c\/what-is-switch-statement-in-c-with-example\/","og_locale":"en_US","og_type":"article","og_title":"What is Switch Statement in C with example ? - Switch Case in C","og_description":"What is Switch Statement in C with example ? - Switch statement is an alternative to if else ladder statement which allows us to execute multiple operations for different values.","og_url":"https:\/\/www.wikitechy.com\/interview-questions\/c\/what-is-switch-statement-in-c-with-example\/","og_site_name":"Wikitechy","article_published_time":"2022-10-03T06:56:02+00:00","article_modified_time":"2022-10-03T07:00:53+00:00","og_image":[{"url":"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/10\/switch-statement-in-c.png"}],"author":"webmaster","twitter_card":"summary_large_image","twitter_misc":{"Written by":"webmaster","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wikitechy.com\/interview-questions\/c\/what-is-switch-statement-in-c-with-example\/","url":"https:\/\/www.wikitechy.com\/interview-questions\/c\/what-is-switch-statement-in-c-with-example\/","name":"What is Switch Statement in C with example ? - Switch Case in C","isPartOf":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/c\/what-is-switch-statement-in-c-with-example\/#primaryimage"},"image":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/c\/what-is-switch-statement-in-c-with-example\/#primaryimage"},"thumbnailUrl":"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/10\/switch-statement-in-c.png","datePublished":"2022-10-03T06:56:02+00:00","dateModified":"2022-10-03T07:00:53+00:00","author":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/f785ba3ecc599133e65ab6138042a3e4"},"description":"What is Switch Statement in C with example ? - Switch statement is an alternative to if else ladder statement which allows us to execute multiple operations for different values.","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wikitechy.com\/interview-questions\/c\/what-is-switch-statement-in-c-with-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.wikitechy.com\/interview-questions\/c\/what-is-switch-statement-in-c-with-example\/#primaryimage","url":"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/10\/switch-statement-in-c.png","contentUrl":"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/10\/switch-statement-in-c.png","width":730,"height":590},{"@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\/4911","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=4911"}],"version-history":[{"count":3,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/4911\/revisions"}],"predecessor-version":[{"id":4917,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/4911\/revisions\/4917"}],"wp:attachment":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/media?parent=4911"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/categories?post=4911"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/tags?post=4911"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}