{"id":4768,"date":"2022-08-18T10:41:19","date_gmt":"2022-08-18T10:41:19","guid":{"rendered":"https:\/\/www.wikitechy.com\/interview-questions\/?p=4768"},"modified":"2022-08-18T10:41:50","modified_gmt":"2022-08-18T10:41:50","slug":"what-is-constructor-in-cpp","status":"publish","type":"post","link":"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-constructor-in-cpp\/","title":{"rendered":"What is Constructor in C++ ?"},"content":{"rendered":"<ul>\n<li style=\"text-align: justify;\">In C++ constructor is a special type of member function of a class which initializes objects of a class.<\/li>\n<li style=\"text-align: justify;\">Constructor is automatically called when object is created in C++.<\/li>\n<li style=\"text-align: justify;\">It does not have any return type because it is special member function of the class.<\/li>\n<li style=\"text-align: justify;\">In public section of class and it has same name as the class itself.<\/li>\n<li style=\"text-align: justify;\">Copy and parameterized constructors have input arguments, by default constructors don\u2019t have input argument however.<\/li>\n<li style=\"text-align: justify;\">C++ compiler generates a default constructor for object, if we do not\u00a0specify a constructor.<\/li>\n<li style=\"text-align: justify;\">In constructor there are three types, they are <strong>default constructor, parameterized constructor, copy constructor.<\/strong><\/li>\n<\/ul>\n<p><img fetchpriority=\"high\" decoding=\"async\" class=\"alignnone size-full wp-image-4772 aligncenter\" src=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/constructor-in-c.png\" alt=\"\" width=\"1759\" height=\"709\" srcset=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/constructor-in-c.png 1759w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/constructor-in-c-300x121.png 300w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/constructor-in-c-1024x413.png 1024w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/constructor-in-c-768x310.png 768w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/constructor-in-c-1536x619.png 1536w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/constructor-in-c-390x157.png 390w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/constructor-in-c-820x331.png 820w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/constructor-in-c-1180x476.png 1180w\" sizes=\"(max-width: 1759px) 100vw, 1759px\" \/><\/p>\n<h2 id=\"default-constructor\">Default Constructor<\/h2>\n<ul>\n<li>It is the constructor which has no parameters and doesn\u2019t take any argument.<\/li>\n<\/ul>\n<h3 id=\"sample-code\"><strong>Sample Code<\/strong><\/h3>\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\/><br\/>class construct<br\/><br\/>{<br\/><br\/>public:<br\/><br\/>\u00a0\u00a0\u00a0\u00a0int a, b;<br\/><br\/><br\/><br\/><br\/>\u00a0\u00a0\u00a0\u00a0\/\/ Default Constructor<br\/><br\/>\u00a0\u00a0\u00a0\u00a0construct()<br\/><br\/>\u00a0\u00a0\u00a0\u00a0{<br\/><br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0a = 30;<br\/><br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0b = 40;<br\/><br\/>\u00a0\u00a0\u00a0\u00a0}<br\/><br\/>};<br\/><br\/><br\/><br\/><br\/>int main()<br\/><br\/>{<br\/><br\/>\u00a0\u00a0\u00a0\u00a0\/\/ Default constructor called automatically<br\/><br\/>\u00a0\u00a0\u00a0\u00a0\/\/ when the object is created<br\/><br\/>\u00a0\u00a0\u00a0\u00a0construct c;<br\/><br\/>\u00a0\u00a0\u00a0\u00a0cout << &quot;a: &quot; << c.a << endl<br\/><br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<< &quot;b: &quot; << c.b;<br\/><br\/>\u00a0\u00a0\u00a0\u00a0return 1;<br\/><br\/>}<\/code><\/pre> <\/div>\n<h3 id=\"output\"><strong>Output<\/strong><\/h3>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-4769\" src=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/default-constructor.png\" alt=\"\" width=\"969\" height=\"178\" srcset=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/default-constructor.png 969w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/default-constructor-300x55.png 300w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/default-constructor-768x141.png 768w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/default-constructor-390x72.png 390w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/default-constructor-820x151.png 820w\" sizes=\"(max-width: 969px) 100vw, 969px\" \/><\/p>\n<h2 id=\"parameterized-constructor\">Parameterized Constructor<\/h2>\n<ul>\n<li>It is possible to pass arguments to constructors and these arguments help initialize an object when it is created typically.<\/li>\n<\/ul>\n<h3 id=\"sample-code-2\"><strong>Sample Code<\/strong><\/h3>\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\/><br\/>class Point<br\/><br\/>{<br\/><br\/>private:<br\/><br\/>\u00a0\u00a0\u00a0\u00a0int x, y;<br\/><br\/><br\/><br\/><br\/>public:<br\/><br\/>\u00a0\u00a0\u00a0\u00a0\/\/ Parameterized Constructor<br\/><br\/>\u00a0\u00a0\u00a0\u00a0Point(int x1, int y1)<br\/><br\/>\u00a0\u00a0\u00a0\u00a0{<br\/><br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0x = x1;<br\/><br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0y = y1;<br\/><br\/>\u00a0\u00a0\u00a0\u00a0}<br\/><br\/><br\/><br\/><br\/>\u00a0\u00a0\u00a0\u00a0int getX()<br\/><br\/>\u00a0\u00a0\u00a0\u00a0{<br\/><br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return x;<br\/><br\/>\u00a0\u00a0\u00a0\u00a0}<br\/><br\/>\u00a0\u00a0\u00a0\u00a0int getY()<br\/><br\/>\u00a0\u00a0\u00a0\u00a0{<br\/><br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return y;<br\/><br\/>\u00a0\u00a0\u00a0\u00a0}<br\/><br\/>};<br\/><br\/><br\/><br\/><br\/>int main()<br\/><br\/>{<br\/><br\/>\u00a0\u00a0\u00a0\u00a0\/\/ Constructor called<br\/><br\/>\u00a0\u00a0\u00a0\u00a0Point p1(10, 15);<br\/><br\/><br\/><br\/><br\/>\u00a0\u00a0\u00a0\u00a0\/\/ Access values assigned by constructor<br\/><br\/>\u00a0\u00a0\u00a0\u00a0cout << &quot;p1.x = &quot; << p1.getX() << &quot;, p1.y = &quot; << p1.getY();<br\/><br\/><br\/><br\/><br\/>\u00a0\u00a0\u00a0\u00a0return 0;<br\/><br\/>}<\/code><\/pre> <\/div>\n<h3 id=\"output-2\"><strong>\u00a0O<\/strong><strong>utput<\/strong><\/h3>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-4770\" src=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/parameterized-constructor.png\" alt=\"\" width=\"934\" height=\"181\" srcset=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/parameterized-constructor.png 934w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/parameterized-constructor-300x58.png 300w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/parameterized-constructor-768x149.png 768w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/parameterized-constructor-390x76.png 390w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/parameterized-constructor-820x159.png 820w\" sizes=\"(max-width: 934px) 100vw, 934px\" \/><\/p>\n<h2 id=\"copy-constructor\">Copy Constructor<\/h2>\n<ul>\n<li>It is a member function which initializes an object using another object of the same class.<\/li>\n<\/ul>\n<h3 id=\"sample-code-3\"><strong>Sample Code<\/strong><\/h3>\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\/><br\/>class point<br\/><br\/>{<br\/><br\/>private:<br\/><br\/>\u00a0\u00a0double x, y;<br\/><br\/><br\/><br\/><br\/>public:<br\/><br\/>\u00a0\u00a0\u00a0<br\/><br\/>\u00a0\u00a0\/\/ Non-default Constructor &<br\/><br\/>\u00a0\u00a0\/\/ default Constructor<br\/><br\/>\u00a0\u00a0point (double px, double py)<br\/><br\/>\u00a0\u00a0{<br\/><br\/>\u00a0\u00a0\u00a0\u00a0x = px, y = py;<br\/><br\/>\u00a0\u00a0}<br\/><br\/>};<br\/><br\/><br\/><br\/><br\/>int main(void)<br\/><br\/>{<br\/><br\/><br\/><br\/><br\/>\u00a0\u00a0\/\/ Define an array of size<br\/><br\/>\u00a0\u00a0\/\/ 10 & of type point<br\/><br\/>\u00a0\u00a0\/\/ This line will cause error<br\/><br\/>\u00a0\u00a0point a[10];<br\/><br\/><br\/><br\/><br\/>\u00a0\u00a0\/\/ Remove above line and program<br\/><br\/>\u00a0\u00a0\/\/ will compile without error<br\/><br\/>\u00a0\u00a0point b = point(5, 6);<br\/><br\/>}<\/code><\/pre> <\/div>\n<h3 id=\"output-3\"><strong>Output<\/strong><\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4771\" src=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/copy-constructor.png\" alt=\"\" width=\"1053\" height=\"189\" srcset=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/copy-constructor.png 1053w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/copy-constructor-300x54.png 300w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/copy-constructor-1024x184.png 1024w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/copy-constructor-768x138.png 768w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/copy-constructor-390x70.png 390w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/copy-constructor-820x147.png 820w\" sizes=\"(max-width: 1053px) 100vw, 1053px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In C++ constructor is a special type of member function of a class which initializes objects of a class. Constructor is automatically called when object is created in C++. It does not have any return type because it is special member function of the class. In public section of class and it has same name [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2080],"tags":[18354,18352,18362,18353,18361,18351,18355,18359,18357,18356,18358,18360],"class_list":["post-4768","post","type-post","status-publish","format-standard","hentry","category-cpp","tag-c-class-constructor-and-destructor","tag-c-constructors","tag-constructor-and-destructor-in-c","tag-constructor-in-c-and-its-types","tag-constructor-overloading-in-c","tag-constructors-in-c","tag-types-of-constructor-in-c","tag-types-of-constructor-in-c-with-example","tag-use-of-constructor-in-c","tag-what-is-copy-constructor-in-c","tag-what-is-default-constructor-in-c","tag-what-is-parameterized-constructor-in-c"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>What is Constructor in C++ - Constructors in C++ - C++ Constructors<\/title>\n<meta name=\"description\" content=\"What is Constructor in C++ - In C++ constructor is a special type of member function of a class which initializes objects of a class.\" \/>\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-constructor-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 Constructor in C++ - Constructors in C++ - C++ Constructors\" \/>\n<meta property=\"og:description\" content=\"What is Constructor in C++ - In C++ constructor is a special type of member function of a class which initializes objects of a class.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-constructor-in-cpp\/\" \/>\n<meta property=\"og:site_name\" content=\"Wikitechy\" \/>\n<meta property=\"article:published_time\" content=\"2022-08-18T10:41:19+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-08-18T10:41:50+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/constructor-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=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/cpp\\\/what-is-constructor-in-cpp\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/cpp\\\/what-is-constructor-in-cpp\\\/\"},\"author\":{\"name\":\"webmaster\",\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/#\\\/schema\\\/person\\\/f785ba3ecc599133e65ab6138042a3e4\"},\"headline\":\"What is Constructor in C++ ?\",\"datePublished\":\"2022-08-18T10:41:19+00:00\",\"dateModified\":\"2022-08-18T10:41:50+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/cpp\\\/what-is-constructor-in-cpp\\\/\"},\"wordCount\":1007,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/cpp\\\/what-is-constructor-in-cpp\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/constructor-in-c.png\",\"keywords\":[\"c++ class constructor and destructor\",\"c++ constructors\",\"constructor and destructor in c++\",\"Constructor in c++ and its types\",\"constructor overloading in c++\",\"constructors in c++\",\"types of constructor in c++\",\"types of constructor in c++ with example\",\"use of constructor in c++\",\"what is copy constructor in c++\",\"what is default constructor in c++\",\"what is parameterized constructor in c++\"],\"articleSection\":[\"C++\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/cpp\\\/what-is-constructor-in-cpp\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/cpp\\\/what-is-constructor-in-cpp\\\/\",\"url\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/cpp\\\/what-is-constructor-in-cpp\\\/\",\"name\":\"What is Constructor in C++ - Constructors in C++ - C++ Constructors\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/cpp\\\/what-is-constructor-in-cpp\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/cpp\\\/what-is-constructor-in-cpp\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/constructor-in-c.png\",\"datePublished\":\"2022-08-18T10:41:19+00:00\",\"dateModified\":\"2022-08-18T10:41:50+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/#\\\/schema\\\/person\\\/f785ba3ecc599133e65ab6138042a3e4\"},\"description\":\"What is Constructor in C++ - In C++ constructor is a special type of member function of a class which initializes objects of a class.\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/cpp\\\/what-is-constructor-in-cpp\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/cpp\\\/what-is-constructor-in-cpp\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/constructor-in-c.png\",\"contentUrl\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/constructor-in-c.png\",\"width\":1759,\"height\":709},{\"@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\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"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:\\\/\\\/secure.gravatar.com\\\/avatar\\\/155b77fd8cdda3d0913fcb7e7ee63543b0c345d2d8f6dcebda5b0583ab61f967?s=96&d=mm&r=g\",\"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 Constructor in C++ - Constructors in C++ - C++ Constructors","description":"What is Constructor in C++ - In C++ constructor is a special type of member function of a class which initializes objects of a class.","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-constructor-in-cpp\/","og_locale":"en_US","og_type":"article","og_title":"What is Constructor in C++ - Constructors in C++ - C++ Constructors","og_description":"What is Constructor in C++ - In C++ constructor is a special type of member function of a class which initializes objects of a class.","og_url":"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-constructor-in-cpp\/","og_site_name":"Wikitechy","article_published_time":"2022-08-18T10:41:19+00:00","article_modified_time":"2022-08-18T10:41:50+00:00","og_image":[{"url":"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/constructor-in-c.png","type":"","width":"","height":""}],"author":"webmaster","twitter_card":"summary_large_image","twitter_misc":{"Written by":"webmaster","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-constructor-in-cpp\/#article","isPartOf":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-constructor-in-cpp\/"},"author":{"name":"webmaster","@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/f785ba3ecc599133e65ab6138042a3e4"},"headline":"What is Constructor in C++ ?","datePublished":"2022-08-18T10:41:19+00:00","dateModified":"2022-08-18T10:41:50+00:00","mainEntityOfPage":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-constructor-in-cpp\/"},"wordCount":1007,"commentCount":0,"image":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-constructor-in-cpp\/#primaryimage"},"thumbnailUrl":"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/constructor-in-c.png","keywords":["c++ class constructor and destructor","c++ constructors","constructor and destructor in c++","Constructor in c++ and its types","constructor overloading in c++","constructors in c++","types of constructor in c++","types of constructor in c++ with example","use of constructor in c++","what is copy constructor in c++","what is default constructor in c++","what is parameterized constructor in c++"],"articleSection":["C++"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-constructor-in-cpp\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-constructor-in-cpp\/","url":"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-constructor-in-cpp\/","name":"What is Constructor in C++ - Constructors in C++ - C++ Constructors","isPartOf":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-constructor-in-cpp\/#primaryimage"},"image":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-constructor-in-cpp\/#primaryimage"},"thumbnailUrl":"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/constructor-in-c.png","datePublished":"2022-08-18T10:41:19+00:00","dateModified":"2022-08-18T10:41:50+00:00","author":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/f785ba3ecc599133e65ab6138042a3e4"},"description":"What is Constructor in C++ - In C++ constructor is a special type of member function of a class which initializes objects of a class.","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-constructor-in-cpp\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-constructor-in-cpp\/#primaryimage","url":"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/constructor-in-c.png","contentUrl":"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/constructor-in-c.png","width":1759,"height":709},{"@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":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"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:\/\/secure.gravatar.com\/avatar\/155b77fd8cdda3d0913fcb7e7ee63543b0c345d2d8f6dcebda5b0583ab61f967?s=96&d=mm&r=g","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\/4768","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=4768"}],"version-history":[{"count":1,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/4768\/revisions"}],"predecessor-version":[{"id":4773,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/4768\/revisions\/4773"}],"wp:attachment":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/media?parent=4768"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/categories?post=4768"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/tags?post=4768"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}