What is Constructor in c++ in hindi with example

What is Constructor in c++ in hindi with example:- Hello Friend’s, This is shubham And i am Back With this QA Series Of C++. In this Series you Will Gets Most important Question’s And Answers’s For Your Exam.. Show Let’s Get Started… As You Can See in The Title Here is our Third Question..

 

Q.3. – What is Constructor in c++ in hindi (

Constructor kya hai) ?

Constructor ek tarah ka member Function hota hai. Jo ki class me Kisi bhi prakar ke Object Ko Initialize Karta hai. Constructor Ke bare me Kuch important point hai Jo main Apko Batana Cahugaa.

  • Name of Constructor is based on Class (Same as Class)
  • It doesn’t required “void” also no return type as Function.
  • it Runs automatically as object of class created.
  • Constructor is a special member of class can be used to initiate  The object of class.
  • it is best way to initiate the Object.

jab class me Koi bhi New Object Create kiya jaata Hai To Constructor call hota hai Aur Usme diye Sabhi Statement Execute Hote hai. Constructor ko Class ke Ander Bhi Define kiya ja Sakta hai Aur bahar Bhi define kiya jaa Sakta hai. To hear is The example Of Constructor. “What is Constructor in c++ in hindi with example

#include<iostream.h>

#include<conio.h>

#include<string.h>

class student

{private:

int rno;

char name[20];

char cls[15];

int fees;  

public:

void get()

{ cout<<“Enter roll no= “;      cin>>ron;

cout<<“Enter Student Name= “;    cin>>name;

cout<<“Enter Class= “;     cin>>cls;

cout<<“Enter Fees= “;     cin>>fees;

}    void show()

{  cout<<rno<<“\t”<<name<<“\t”<<cls<<“\t”<<fees;

}  

student()

{rno = 1501;

strcpy(name , “Ravi”);

strcpy(cls , “Bsc(cs)”);

fees = 6000;

}  };

void main()

{ clrscr();

student s1, s2;

s2.get();

s1.show();

s2.show();

getch();

}

iss Program me Jo Values maine Constructor Me provide ki hai. jab Ham s1 object me show()  function ka Use karege To hame Constructor ki values Show Hogi kyuki Hamne s1 Object me Data input nahi kiya hai.. ” What is Constructor in c++ in hindi with example”

To guys Apko Meri Ye Post What is Constructor in c++ in hindi with example  kaisi Lagi Hame Jarur Bataye Apne Comments Ke madhyam Se.. Aur Koi Q Ho To Aap Hamse Puch Sakte Hai.. Post Achi Lagi To Share Karna Na Bhule..

Comments

  1. By Deepak

    Reply

    • By Shubham

      Reply

  2. By Anju

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

Show Buttons
Hide Buttons