by Dinesh Thakur Category: Array Pointer and Union

 

#include<iostream.h>

#include<conio.h>
#include<string.h>
class string
{
      char *nm;
       int len;
       public:
             string(char *s)
          {
             len=strlen(s);
             nm=new char[len+ 1];
             strcpy(nm,s);
          }
             void com(string &ss2)
         {
             int k;
             k=strcmp(nm,ss2.nm);
             if(k==0)
             cout<<"\nBoth objects have same name";
             else
             cout<<"\nBoth objects have different name";
         }
             void put()
           {
                 cout<<"\nName of person : "<<nm;
            }
              ~string()
            {
                 cout<<"\nRelease memory allocated to"<<nm;
                 delete[] nm;
             }
 };
                  void main()
         {
               clrscr();
               string obj1 ("Dinesh");
               string obj2("Thakur");
               obj1.put();
               obj2.put();
               obj1.com(obj2);
               getch();
         }

Depict Working Of Constructor & Destructor In Operations Performed Dynamically



About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.



Related Articles