<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":4814,"date":"2022-08-19T12:20:28","date_gmt":"2022-08-19T12:20:28","guid":{"rendered":"https:\/\/www.wikitechy.com\/interview-questions\/?p=4814"},"modified":"2022-08-19T12:20:51","modified_gmt":"2022-08-19T12:20:51","slug":"what-is-namespace-in-cpp","status":"publish","type":"post","link":"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-namespace-in-cpp\/","title":{"rendered":"What is namespace in C++ ?"},"content":{"rendered":"<ul>\n<li style=\"text-align: justify;\">In C++ namespace is a logical division of the code which is designed to stop the naming conflict.<\/li>\n<li style=\"text-align: justify;\">In C++ namespace defines the scope where the identifiers such as variables, class, functions are declared.<\/li>\n<li style=\"text-align: justify;\">The main purpose of using namespace is to remove the ambiguity in C++. If different task occurs with the same name their ambiguity occurs.<\/li>\n<li style=\"text-align: justify;\">In different namespaces functions are declared, for example if there are two functions exist with the same name such as add (), In order to prevent this ambiguity, the namespace is used.<\/li>\n<li style=\"text-align: justify;\">C++ language consists of a standard namespace\u00a0which contains inbuilt classes and functions.<\/li>\n<li style=\"text-align: justify;\">In our program by using the statement &#8220;using namespace std;&#8221; includes the namespace &#8220;std&#8221;.<\/li>\n<\/ul>\n<h2 id=\"syntax\">Syntax<\/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\">namespace namespace_name  <br\/>{  <br\/>     \/\/body of namespace;  <br\/>}  <\/code><\/pre> <\/div>\n<h2 id=\"syntax-of-accessing-the-namespace-variable\">Syntax of accessing the namespace variable<\/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\">namespace_name::member_name; <\/code><\/pre> <\/div>\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\"> using namespace std;  <br\/>namespace addition  <br\/>{  <br\/>    int a=5;  <br\/>    int b=5;  <br\/>    int add()  <br\/>    {  <br\/>        return(a+b);  <br\/>    }  <br\/>}  <br\/>  <br\/>int main() {  <br\/>int result;  <br\/>result=addition::add();  <br\/>cout&lt;&lt;result;  <br\/>return 0;  <br\/>      }  <\/code><\/pre> <\/div>\n<h2 id=\"output\">Output<\/h2>\n<p><img fetchpriority=\"high\" decoding=\"async\" class=\"alignnone size-full wp-image-4815\" src=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/namespace-1.png\" alt=\"\" width=\"1396\" height=\"117\" srcset=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/namespace-1.png 1396w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/namespace-1-300x25.png 300w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/namespace-1-1024x86.png 1024w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/namespace-1-768x64.png 768w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/namespace-1-390x33.png 390w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/namespace-1-820x69.png 820w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/namespace-1-1180x99.png 1180w\" sizes=\"(max-width: 1396px) 100vw, 1396px\" \/><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In C++ namespace is a logical division of the code which is designed to stop the naming conflict. In C++ namespace defines the scope where the identifiers such as variables, class, functions are declared. The main purpose of using namespace is to remove the ambiguity in C++. If different task occurs with the same name [&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":[18467,18466,18468,18470,18464,18164,18474,18463,18469,18471,18473,18472,18465],"class_list":["post-4814","post","type-post","status-publish","format-standard","hentry","category-cpp","tag-advantages-of-namespace-in-c","tag-namespace-example","tag-namespace-in-c","tag-what-is-namespace-in-c-plus-plus","tag-what-is-namespace-in-c","tag-what-is-namespace-in-c-with-example","tag-what-is-namespace-in-cpp","tag-what-is-namespace-std-in-c","tag-what-is-std-in-c","tag-what-is-the-purpose-of-namespace-in-c","tag-what-is-the-use-of-namespace-in-c","tag-what-is-using-namespace-std-in-c-plus-plus","tag-what-is-using-namespace-std-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 namespace in C++ ?<\/title>\n<meta name=\"description\" content=\"What is namespace in C++ ? - In C++ namespace is a logical division of the code which is designed to stop the naming conflict.\" \/>\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-namespace-in-cpp\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"What is namespace in C++ ?\" \/>\n<meta property=\"og:description\" content=\"What is namespace in C++ ? - In C++ namespace is a logical division of the code which is designed to stop the naming conflict.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-namespace-in-cpp\/\" \/>\n<meta property=\"og:site_name\" content=\"Wikitechy\" \/>\n<meta property=\"article:published_time\" content=\"2022-08-19T12:20:28+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-08-19T12:20:51+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/namespace-1.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\/cpp\/what-is-namespace-in-cpp\/\",\"url\":\"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-namespace-in-cpp\/\",\"name\":\"What is namespace in C++ ?\",\"isPartOf\":{\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-namespace-in-cpp\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-namespace-in-cpp\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/namespace-1.png\",\"datePublished\":\"2022-08-19T12:20:28+00:00\",\"dateModified\":\"2022-08-19T12:20:51+00:00\",\"author\":{\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/f785ba3ecc599133e65ab6138042a3e4\"},\"description\":\"What is namespace in C++ ? - In C++ namespace is a logical division of the code which is designed to stop the naming conflict.\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-namespace-in-cpp\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-namespace-in-cpp\/#primaryimage\",\"url\":\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/namespace-1.png\",\"contentUrl\":\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/namespace-1.png\",\"width\":1396,\"height\":117},{\"@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 namespace in C++ ?","description":"What is namespace in C++ ? - In C++ namespace is a logical division of the code which is designed to stop the naming conflict.","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-namespace-in-cpp\/","og_locale":"en_US","og_type":"article","og_title":"What is namespace in C++ ?","og_description":"What is namespace in C++ ? - In C++ namespace is a logical division of the code which is designed to stop the naming conflict.","og_url":"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-namespace-in-cpp\/","og_site_name":"Wikitechy","article_published_time":"2022-08-19T12:20:28+00:00","article_modified_time":"2022-08-19T12:20:51+00:00","og_image":[{"url":"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/namespace-1.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\/cpp\/what-is-namespace-in-cpp\/","url":"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-namespace-in-cpp\/","name":"What is namespace in C++ ?","isPartOf":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-namespace-in-cpp\/#primaryimage"},"image":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-namespace-in-cpp\/#primaryimage"},"thumbnailUrl":"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/namespace-1.png","datePublished":"2022-08-19T12:20:28+00:00","dateModified":"2022-08-19T12:20:51+00:00","author":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/f785ba3ecc599133e65ab6138042a3e4"},"description":"What is namespace in C++ ? - In C++ namespace is a logical division of the code which is designed to stop the naming conflict.","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-namespace-in-cpp\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-namespace-in-cpp\/#primaryimage","url":"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/namespace-1.png","contentUrl":"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/namespace-1.png","width":1396,"height":117},{"@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\/4814","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=4814"}],"version-history":[{"count":1,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/4814\/revisions"}],"predecessor-version":[{"id":4816,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/4814\/revisions\/4816"}],"wp:attachment":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/media?parent=4814"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/categories?post=4814"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/tags?post=4814"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}