Tuesday, 1 May 2018

How to enable inbuilt Linux subsytem in Windows 10

Windows 10 provide inbuilt Linux subsystem , lets see how to enable it in your System.

Step 1 :   Go to Windows update and change uses mode to Developer Mode
select developer Mode in Windows update

Sunday, 1 October 2017

How to check Palindrome

Check if a string is palindrome or not is one of most common question we encountered during our basic days.

Let's Solve this problem with a Naive but efficient approach in this case.

Pseudocode :

  1. i=0, j=n
  2. while i < j:
  3.    check if i'th element is not equal to j'th
  4.      then return False 
  5.   else i++,j--
  6. loop end
  7. return True

Monday, 27 June 2016

When to use our own copy constructor while compiler already provides it


Actually compiler provided copy constructor copies all the values of members. So we are using a dynamic allocated member then only address of that member is copied in new object's member. It does not allocate new memory.

  1. #include <iostream>
  2. #include<cstring>
  3. #include<cstdio>
  4. using namespace std;
  5. class XYZ
  6. {
  7.     public:
  8.     char *p;
  9.     XYZ(char *name,int l){
  10.         p=new char[l+1];
  11.         strcpy(p,name);
  12.        
  13.     }
  14. };
  15. int main() {
  16.     XYZ obj1("str",3);
  17.     printf("content of obj1.p is : %u\n",obj1.p);
  18.     XYZ obj2=obj1;
  19.     printf("content of obj2.p is : %u",obj2.p);
  20. }
So here content of member p of obj1 and obj2 is same which is base address of string str
Note that memory is allocated once and pointer to that memory is set for both objects. So default copy constructor only copying members value that is value of obj1.p ( which is address of string "str" ) is copied to obj2.p

Blogger Widgets