{"id":2321,"date":"2024-11-06T11:26:02","date_gmt":"2024-11-06T11:26:02","guid":{"rendered":"https:\/\/itnotes.apjsoftwares.in\/?p=2321"},"modified":"2024-11-06T11:26:02","modified_gmt":"2024-11-06T11:26:02","slug":"switch-case-and-default","status":"publish","type":"post","link":"https:\/\/itnotes.apjsoftwares.in\/index.php\/2024\/11\/06\/switch-case-and-default\/","title":{"rendered":"switch, case, and default"},"content":{"rendered":"\n<p>The switch statement in C is used as an alternate to the if-else ladder statement. For a single variable i.e, switch variable it allows us to execute multiple operations for different possible values of a single variable.&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">switch(Expression)<br>{<br>    case '1': \/\/ operation 1<br>            break;<br>    case:'2': \/\/ operation 2<br>            break;<br>    default: \/\/ default statement to be executed <br>}<\/pre>\n\n\n\n<p><span style=\"color: rgb(39, 50, 57); font-family: Nunito, sans-serif; letter-spacing: 0.162px; white-space-collapse: collapse;\">Below is the C program to demonstrate the switch case statement:<\/span><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\r\n#include &lt;stdio.h>\r\nint main() {\r\n  int i = 2;\r\n  switch (i) {\r\n    case 1: \r\n      printf(\"Case 1\\n\");\n      break;\r\n    case 2:\r\n      printf(\"Case 2\\n\");\n      break;\r\n    case 3:\r\n      printf(\"Case 3\\n\"); \n      break;\r\n    case 4:\r\n      printf(\"Case 4\\n\"); \n      break;\r\n    default:\r\n      printf(\"Default\\n\");\n      break;\r\n  }\r\n}\n\r\n<strong>Output:\r\nCase 2<\/strong><\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The switch statement in C is used as an alternate to the if-else ladder statement&#8230;.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[13],"tags":[],"_links":{"self":[{"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/posts\/2321"}],"collection":[{"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/comments?post=2321"}],"version-history":[{"count":1,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/posts\/2321\/revisions"}],"predecessor-version":[{"id":2323,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/posts\/2321\/revisions\/2323"}],"wp:attachment":[{"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/media?parent=2321"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/categories?post=2321"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/tags?post=2321"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}