Home / C++ Programming / Functions - C++ :: Programs

C++ Programming :: Functions - C++

  1. What will be the output of the following program?

       #include
       class TestDrive 
       {    
            int x;    
            public:     
            TestDrive(int xx)    
            {   
               x = xx;  
            }    
            int DriveIt(void); 
      }; 
      int TestDrive::DriveIt(void)
      {    
          static int value = 0;   
          int m;    
          m = x % 2;     
          x = x / 2; 
          if((x / 2)) DriveIt();    
          value = value + m * 10;    
          return value; 
         } 
         int main() 
         {     
            TestDrive TD(1234);  
            cout10     
            return 0; 
        }
    

  2. A.

    300

    B.

    200

    C.

    Garbage value

    D.

    400

    View Answer

    Workspace

    Discuss Discuss in Forum


  3. What will be the output of the following program?

     #include 
     class Freshergate
     {   
           int Num;  
           public:     
           Freshergate(int x)    
           {       
               Num = x;    
           }     
          int GATEFunction(void);
     };
     int Fresheragte: GATEFunction(void) 
     {   
         static int Sum = 0;   
         int Dec;    
         Dec = Num % 10;      
         Num = Num / 10;      
         if((Num / 100)) GateFunction();    
         sum  = Sum * 10 + Dec; 
         return Sum;
     } 
     int main()
     {   
        Fresheragate objGATE(12345);   
        coutobjGATE.GATEFunction
        return 0;
     }
    

  4. A.

    123

    B.

    321

    C.

    345

    D.

    12345

    E.

    54321

    View Answer

    Workspace

    Discuss Discuss in Forum


  5. What is correct about the following program?

      #include
      class Addition 
      {   
          int x;  
          public:   
         Addition()     
         {      
             x = 0;     
         }           
         Addition(int xx)     
        { 
            x = xx;     
        }
        Addition operator+int xx = 0)     
       {
              Addition objTemp;    
              objTemp.x = x + xx;          
              return(objTemp);   
       }  
       void Display(void)   
       {     
           coutint main()
     {  
         Addition objA(15), objB;  
         objB = objA + 5;  
         objB.Display();     
         return 0;  
    }
    

  6. A.

    The program will print the output 20.

    B.

    The program will report run time error.

    C.

    The program will print the garbage value.

    D.

    Compilation fails due to 'operator +' cannot have default arguments.

    View Answer

    Workspace

    Discuss Discuss in Forum


  7. What will be the output of the following program?

      #include
      class Freshergate
      {    
           public:   
           int x, y;   
           Freshergate(int xx = 10, int yy = 20)    
          {          
               x = xx;       
               y = yy;   
         }   
           void Exchange(int *, int *); 
      }; 
      int main() 
      {    
         Freshergate objA(30, 40);   
         Freshergate objB(50);      
         objA.Exchange(&objA.x, &objB.y);      
         cout" "  
         return 0; 
     }
     void Fresherate::Exchange(int *x, int *y)
     {   
           int t;  
           t  = *x;    
           *x = *y;    
           *y = t ;  
    }  
    

  8. A.

    20 10

    B.

    30 20

    C.

    20 30

    D.

    30 40

    E.

    50 30

    View Answer

    Workspace

    Discuss Discuss in Forum


  9. Which of the following statement is correct about the program given below?

      #include
      classGATEArray
      {  
          int Matrix[3][3];  
          public:   
          GATEArray()  
         {    
            for(int i = 0; i3; i++)            
               for(int j = 0; j 3; j++)                
                  Matrix[j][i] = i + j;   
        } 
        void Display(void)   
        {     
             for(int i = 0; i 3; i++)             
                for(int j = 0; j 3; j++)                
                   cout" ";        
        }
      };  
      int main() 
      {    
          GATEArray objBix;   
          objGATE.Display(); 
          return 0; 
      }

     

  10. A.

    The program will display the output 4 3 2 3 2 1 2 1 0.

    B.

    The program will display the output 0 1 2 1 2 3 2 3 4.

    C.

    The program will display the output 9 garbage values.

    D.

    The program will report error on compilation.

    View Answer

    Workspace

    Discuss Discuss in Forum


  11. What will be the output of the following program?

      #include
      class Freshergate
      {   
          int x, y, z;   
          public:   
          void Apply(int xx = 12, int yy = 21, int zz = 9)       
          {     
              x = xx;   
              y = yy += 10;   
              z = x -= 2;    
         }   
         void Display(void) 
         {     
             cout" " void SetValue(int xx, int yy)  
         {       
            Apply(xx, 0, yy);   
         }
     };
     int main()
     {   
         Freshergate *pGate= new Freshergate;    
         (*pGate).SetValue(12, 20);  
          pGate->Display();   
          delete pGate;   
          return 0; 
     }
    

  12. A.

    10 10

    B.

    12 10

    C.

    12 21

    D.

    12 31

    E.

    The program will report compilation error.

    View Answer

    Workspace

    Discuss Discuss in Forum


  13. What will be the output of the following program?

     #include
     #include  
     class Freshergate
     {    
         char txtMsg[50];   
         public:     
         Freshergate(char *str = NULL)    
         {   
           if(str != NULL)          
             strcpy(txtMsg, str);  
         }  
         int GateFunction(char ch); 
     }; 
     int Freshergate::GateFunction(char ch) 
     {    
         static int i = 0;   
         if(txtMsg[i++] == ch)     
            return strlen((txtMsg + i)) - i;     
         else     
            return GateFunction(ch); 
      } 
      int main() 
      {   
      Freshergate objGate("Welcome to    
      Freshergate.com!");  
      cout't');     
      return 0;
     }
    

  14. A.

    6

    B.

    8

    C.

    9

    D.

    15

    E.

    16

    View Answer

    Workspace

    Discuss Discuss in Forum


  15. Which of the following statement is correct about the program given below?

     #include
     #include
     #include 
      class String
      {   
         char txtName[20];  
         public:   
         GateString(char *txtTemp = NULL) 
         {       
            if(txtTemp != NULL)         
            strcpy(txtName, txtTemp);  
        }   
        void Display(void)  
        {        
             coutint main()
     {  
         char *txtName = (char*)malloc(10);     
         strcpy(txtName, "Freshergate");     
         *txtName = 48; 
          GateString objTemp(txtName);     
          coutsizeof(txtName); 
          return 0;  
     }
    

  16. A.

    Above program will display FresherGATE 8.

    B.

    Above program will display FresherGATE9.

    C.

    Above program will display size of integer.

    D.

    Above program will display FresherGATE and size of integer.

    E.

    Above program will display 1.

    View Answer

    Workspace

    Discuss Discuss in Forum


  17. Which of the following statement is correct about the program given below?

    #include 
     class Freshergate 
     {   
        int x, y, z;   
        public:    
        Freshergate(int x = 100, int y = 30, int z = 0)  
        {      
           this->x = x;   
           this->y = y;     
           this->z = z;       
           Display();     
       }   
       void Display()  
       {     
           cout" " " " int main()
     {    
        int a = 0, b = 1, c = 2;   
        int &x = ++a;    
        int &y = --b;     
        int z = c + b - -c;      
        Freshergate objGate(x, y, z);      
        return 0; 
     }
    

  18. A.

    The program will print the output 1 0 3.

    B.

    The program will print the output 1 0 4.

    C.

    The program will print the output 1 1 3.

    D.

    The program will print the output 1 1 4.

    E.

    The program will report compile time error.

    View Answer

    Workspace

    Discuss Discuss in Forum


  19. Which of the following statement is correct about the program given below?

      #include
      class GateArray 
      {
         int array[3][3];  
         public:   
         GateArray(int arr[3][3] = NULL)   
         {         
            if(arr != NULL)      
            for(int i = 0; i 3; i++)              
               for(int j = 0; j 3; j++)                  
            array[i][j] = i+j; 
        }   
        void Display(void)  
        {      
           for(int i = 0; i 3; i++)              
              for(int j = 0; j 3; j++)                 
                 cout" ";           
       }
     };
     int main()
     {     
        GateArray objBA; 
        objBA.Display();  
        return 0; 
     }
    

  20. A.

    The program will report error on compilation.

    B.

    The program will display 9 garbage values.

    C.

    The program will display NULL 9 times.

    D.

    The program will display 0 1 2 1 2 3 2 3 4.

    View Answer

    Workspace

    Discuss Discuss in Forum