<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":4907,"date":"2022-10-03T06:43:13","date_gmt":"2022-10-03T06:43:13","guid":{"rendered":"https:\/\/www.wikitechy.com\/interview-questions\/?p=4907"},"modified":"2022-10-03T06:44:01","modified_gmt":"2022-10-03T06:44:01","slug":"what-is-static-variable-in-c","status":"publish","type":"post","link":"https:\/\/www.wikitechy.com\/interview-questions\/c\/what-is-static-variable-in-c\/","title":{"rendered":"What is Static Variable in C ?"},"content":{"rendered":"<ul>\n<li style=\"text-align: justify;\">Static variable have a property of preserving their value even after they are out of their scope.<\/li>\n<li style=\"text-align: justify;\">Static variable preserve their previous values in their previous scope and are not initialized again the new scope.<\/li>\n<\/ul>\n<h2 id=\"syntax\" style=\"text-align: justify;\">Syntax<\/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\">static data_type var_name = var_value;<\/code><\/pre> <\/div>\n<ul style=\"text-align: justify;\">\n<li>Here <strong>data_type<\/strong> \u2013&gt; Data types like int, char, float etc.<\/li>\n<li><strong>Var_name<\/strong> -&gt; Name of the variable given by user.<\/li>\n<li><strong>Value<\/strong> -&gt; Any value to initialize. By default, it is zero.<\/li>\n<\/ul>\n<p><img fetchpriority=\"high\" decoding=\"async\" class=\"alignnone size-full wp-image-4908 aligncenter\" src=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/10\/static-variable-in-c.jpg\" alt=\"\" width=\"751\" height=\"377\" srcset=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/10\/static-variable-in-c.jpg 751w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/10\/static-variable-in-c-300x151.jpg 300w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/10\/static-variable-in-c-390x196.jpg 390w\" sizes=\"(max-width: 751px) 100vw, 751px\" \/><\/p>\n<ul style=\"text-align: justify;\">\n<li>A static variable remains in the memory while the program is running.<\/li>\n<li>Static variables are allocated memory in data segment, not in stack segment.<\/li>\n<li>Default values of static variables is assigned as 0 if not initialized explicitly.<\/li>\n<li>In C, static variables can be initialized using constant literals.<\/li>\n<li>Static global variables and functions are possible in C. The purpose of these is to limit scope of a variable or function to file.<\/li>\n<li>Static variables cannot be declared inside the structure. The reason is compiler requires the entire structure elements to be placed together.<\/li>\n<li>Memory allocation for structure members should be contiguous.<\/li>\n<\/ul>\n<p style=\"text-align: justify;\">\n","protected":false},"excerpt":{"rendered":"<p>Static variable have a property of preserving their value even after they are out of their scope. Static variable preserve their previous values in their previous scope and are not initialized again the new scope. Syntax Here data_type \u2013&gt; Data types like int, char, float etc. Var_name -&gt; Name of the variable given by user. [&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":[18738,18743,18745,18742,18741,18735,18744,18737,18734,18740,18736,18739],"class_list":["post-4907","post","type-post","status-publish","format-standard","hentry","category-c","tag-how-to-implement-static-variable-in-c","tag-local-static-variable-in-c","tag-local-static-variables-what-is-their-use","tag-scope-of-static-variable-in-c","tag-static-function-in-c","tag-static-in-c","tag-static-variable-example","tag-static-variable-in-c","tag-static-variables-in-c","tag-static-variables-in-c-programming-language","tag-what-is-the-use-of-static-variable-in-c","tag-why-are-static-variables-used-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 Static Variable in C ? - Why are static variables used in C ?<\/title>\n<meta name=\"description\" content=\"What is Static Variable in C ? - Static variable have a property of preserving their value even after they are out of their scope.\" \/>\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-static-variable-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 Static Variable in C ? - Why are static variables used in C ?\" \/>\n<meta property=\"og:description\" content=\"What is Static Variable in C ? - Static variable have a property of preserving their value even after they are out of their scope.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wikitechy.com\/interview-questions\/c\/what-is-static-variable-in-c\/\" \/>\n<meta property=\"og:site_name\" content=\"Wikitechy\" \/>\n<meta property=\"article:published_time\" content=\"2022-10-03T06:43:13+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-10-03T06:44:01+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/10\/static-variable-in-c.jpg\" \/>\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-static-variable-in-c\/\",\"url\":\"https:\/\/www.wikitechy.com\/interview-questions\/c\/what-is-static-variable-in-c\/\",\"name\":\"What is Static Variable in C ? - Why are static variables used in C ?\",\"isPartOf\":{\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/c\/what-is-static-variable-in-c\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/c\/what-is-static-variable-in-c\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/10\/static-variable-in-c.jpg\",\"datePublished\":\"2022-10-03T06:43:13+00:00\",\"dateModified\":\"2022-10-03T06:44:01+00:00\",\"author\":{\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/f785ba3ecc599133e65ab6138042a3e4\"},\"description\":\"What is Static Variable in C ? - Static variable have a property of preserving their value even after they are out of their scope.\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wikitechy.com\/interview-questions\/c\/what-is-static-variable-in-c\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/c\/what-is-static-variable-in-c\/#primaryimage\",\"url\":\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/10\/static-variable-in-c.jpg\",\"contentUrl\":\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/10\/static-variable-in-c.jpg\",\"width\":751,\"height\":377},{\"@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 Static Variable in C ? - Why are static variables used in C ?","description":"What is Static Variable in C ? - Static variable have a property of preserving their value even after they are out of their scope.","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-static-variable-in-c\/","og_locale":"en_US","og_type":"article","og_title":"What is Static Variable in C ? - Why are static variables used in C ?","og_description":"What is Static Variable in C ? - Static variable have a property of preserving their value even after they are out of their scope.","og_url":"https:\/\/www.wikitechy.com\/interview-questions\/c\/what-is-static-variable-in-c\/","og_site_name":"Wikitechy","article_published_time":"2022-10-03T06:43:13+00:00","article_modified_time":"2022-10-03T06:44:01+00:00","og_image":[{"url":"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/10\/static-variable-in-c.jpg"}],"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-static-variable-in-c\/","url":"https:\/\/www.wikitechy.com\/interview-questions\/c\/what-is-static-variable-in-c\/","name":"What is Static Variable in C ? - Why are static variables used in C ?","isPartOf":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/c\/what-is-static-variable-in-c\/#primaryimage"},"image":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/c\/what-is-static-variable-in-c\/#primaryimage"},"thumbnailUrl":"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/10\/static-variable-in-c.jpg","datePublished":"2022-10-03T06:43:13+00:00","dateModified":"2022-10-03T06:44:01+00:00","author":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/f785ba3ecc599133e65ab6138042a3e4"},"description":"What is Static Variable in C ? - Static variable have a property of preserving their value even after they are out of their scope.","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wikitechy.com\/interview-questions\/c\/what-is-static-variable-in-c\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.wikitechy.com\/interview-questions\/c\/what-is-static-variable-in-c\/#primaryimage","url":"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/10\/static-variable-in-c.jpg","contentUrl":"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/10\/static-variable-in-c.jpg","width":751,"height":377},{"@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\/4907","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=4907"}],"version-history":[{"count":2,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/4907\/revisions"}],"predecessor-version":[{"id":4910,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/4907\/revisions\/4910"}],"wp:attachment":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/media?parent=4907"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/categories?post=4907"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/tags?post=4907"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}