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

C++ Programming :: Functions - C++

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

    
     #include 
     struct Freshergate
     {   
         int arr[5];   
         public:    
         void GATEFunction(void);    
         void Display(void);
     }; 
     void Freshergate::Display(void)
     {   
      for(int i = 0; i 5; i++)          
         cout" " ; 
     }
     void Freshergate::GateFunction(void) 
     {   
        static int i = 0, j = 4;   
        int tmp = arr[i];     
        arr[i]  = arr[j];   
        arr[j]  = tmp   ;     
        i++;   
        j--;   
        if(j != i) GateFunction(); 
    } 
    int main() 
    {    
       Freshergate objGate = {{ 5, 6, 3, 9, 0 }};     
       objGate.GateFunction();     
       objGate.Display();  
       return 0;  
    }
    

  2. A.

    0 9 3 6 5

    B.

    9 3 6 5 0

    C.

    5 6 3 9 0

    D.

    5 9 3 6 0

    View Answer

    Workspace

    Discuss Discuss in Forum


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

    
    
     #include 
      class Freshergate
      {   
          int x;   
          float y;    
          public:   
          Freshergate(int x)     
          {    
             x = x;   
          }    
          Freshergate(int p = 0, int q = 10)   
          {
             x = p += 2;      
             y  = q * 1.0f;  
         }   
         void SetValue(int &y, float z)  
         {        
             x = y;       
             y = (int)z;    
         }     
         void Display(void)     
         {         
             cout int main()
     {    
        int val = 12;    
        FresherGate objGate(val);   
        FresherGate objTmp();     
        objGate.SetValue(val, 3.14f);      
        objGate.Display();  
        return 0;  
     }
    

     

  4. A.

    The program will print the output 2.

    B.

    The program will print the output 12.

    C.

    The program will report run time error.

    D.

    The program will not compile successfully.

    View Answer

    Workspace

    Discuss Discuss in Forum


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

    
     #include 
     struct GateArray 
     {   
         int arr[5];    
         public:    
         void GateFunction();    
         void Display();
     }; 
     void GateArray::GateFunction()
     {     
         static int i = 0, j = 4;  
         i++;   
         j--;    
         if(j > 0)      
             GateFunction();     
        int tmp = arr[i];    
        arr[i]  = arr[j];     
        arr[j]  = tmp;  
        i--;   
        j++; 
     }
     void GateArray::Display()
     {  
        for(int i = 0; i 5; i++)         
          cout" ";
     } 
     int main() 
     {   
         GateArray objArr = {{5, 6, 3, 9, 0}};     
         objArr.GateFunction();     
         objArr.Display(); 
         return 0;  
    

  6. A.

    5 6 3 9 0

    B.

    0 9 3 6 5

    C.

    0 5 6 3 9

    D.

    0 6 3 9 5

    E.

    None of these

    View Answer

    Workspace

    Discuss Discuss in Forum


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

     #include 
     #include 
     class GateString 
     {  
        char x[50];   
        char y[50];    
        char z[50];      
        public:     
        GateString()     
        { }  
        GateString(char* xx)   
        {       
            strcpy(x, xx);      
            strcpy(y, xx);    
        } 
         GateString(char *xx, char *yy = " C++", char *zz = " Programming!")  
        {      
           strcpy(z, xx);  
           strcat(z, yy);     
           strcat(z, zz);  
       }   
       void Display(void)   
        {   
        coutint main() 
      {    
         GateString objStr("Learn", " Java");      
         objStr.Display();  
         return 0;  
      }
    
    

  8. A.

    Java Programming!

    B.

    C++ Programming!

    C.

    Learn C++ Programming!

    D.

    Learn Java Programming!

    E.

    Learn Java C++ Programming!

    View Answer

    Workspace

    Discuss Discuss in Forum


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

      #include
       class BaseCounter
       {    
           protected:   
           long int count;    
        
           public:   
           void CountIt(int x, int y = 10, int z = 20)    
           {         
                count = 0;     
                cout" " " " 0;   
            }     
            BaseCounter(int x)  
            {       
                 count = x ;  
            } 
        };  
        class DerivedCounter: public BaseCounter 
        {   
           public:    
           DerivedCounter() 
           { }   
           DerivedCounter(int x): BaseCounter(x)  
           { } 
      }; 
      int main() 
      {   
          DerivedCounter objDC(30);    
          objDC.CountIt(40, 50);     
          return 0; 
      }
    

  10. A.

    30 10 20

    B.

    Garbage 10 20

    C.

    40 50 20

    D.

    20 40 50

    E.

    40 Garbage Garbage

    View Answer

    Workspace

    Discuss Discuss in Forum


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

      #include 
      class Number
      {    
          int Num;     
          public:     
          Number(int x = 0)    
          {          
              Num = x;  
          }  
          void Display(void)  
          {         
             cout       void Modify(); 
        }; 
        void Number::Modify() 
        {   
           int Dec;   
           Dec = Num % 13;     
           Num = Num / 13;               
           
              if( Num  > 0 ) Modify()   ;     
              if(Dec == 10) cout"A" ;   
           else if(Dec == 11) cout"B" ;     
           else if(Dec == 12) cout"C" ;   
           else if(Dec == 13) cout"D" ;  
           else               cout
    }
    int main() 
    {    
         Number objNum(130);   
         objNum.Modify();     
         return 0;  
    }
    

  12. A.

    130

    B.

    A0

    C.

    B0

    D.

    90

    View Answer

    Workspace

    Discuss Discuss in Forum


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

    
      #include
      class Base
      {    
          int x, y;   
          public:   
          Base()     
          {         
              x = y = 0;    
           }      
           Base(int xx)     
           {      
               x = xx;   
          }   
          Base(int p, int q = 10)   
          {     
              x = p + q;      
              y = q;     
          }     
          void Display(void)    
          {       
             cout" " 1, 1);  
     
      class Derived: public Base
      {    
          Base obj;   
          public:   
          Derived(int xx, int yy): Base(xx, xx + 1)    
          { }     
          Derived(Base objB = objDefault)   
          { }  
     };
     int main()
     {
         Derived objD(5, 3);  
         Derived *ptrD = new Derived(objD);  
         ptrD->Display();   
         delete ptrD;    
         return 0; 
     }
    

  14. A.

    3 2

    B.

    8 3

    C.

    11 6

    D.

    11 10

    E.

    The program will not compile successfully.

    View Answer

    Workspace

    Discuss Discuss in Forum


  15. What is correct about the following program?

       #include 
       class Base 
       {
          int x, y, z;  
          public:  
          Base()    
          {        
              x = y = z = 0;   
          }
          Base(int xx, int yy = 'A', int zz = 'B')     
          {         
               x = xx;     
               y = x + yy;       
               z = x + y;  
        }   
        void Display(void) 
        {      
           cout" " " " class Derived : public Base 
     {    
         int x, y;   
         public:     
         Derived(int xx = 65, int yy = 66) : Base(xx, yy)    
         {        
               y = xx;        
               x = yy;     
        }
        void Display(void)     
        {       
              cout" " " ";   
              Display();    
        } 
     }; 
     int main() 
     {        Derived objD;    
              objD.Display();    
              return 0;  
     }

     

     

  16. A.

    The program will report compilation error.

    B.

    The program will run successfully giving the output 66 65.

    C.

    The program will run successfully giving the output 65 66.

    D.

    The program will run successfully giving the output 66 65 65 131 196.

    E.

    The program will produce the output 66 65 infinite number of times (or till stack memory overflow).

    View Answer

    Workspace

    Discuss Discuss in Forum


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

    
      #include 
       static int Result;
       class Fresher
       {
          public: 
          void Change(int x = 10, int y = 20, int z = 30)   
          {       
             coutvoid Display(int x = 40, float y = 50.00)    
          {     
              Result = x % x;       
              coutclass Gate
      {
           int x, y;   
           public:     
           void Change(int x, int y = 50)    
          {        
            coutclass Freshergate: public Fresher, public Gate
      {    
          public:   
          void Display(int x = 10, int xx = 100, int xxx = 1000)   
          {       
             Result = x + xx % x * x;     
             coutint main()
     {    
         Fresher objGate;    
         objGateFresher::Display(10, 20.00);  
         return 0;  
     }
    

  18. A.

    The program will print the output 0.

    B.

    The program will print the output 10.

    C.

    The program will print the output 30.

    D.

    The program will print the output 40.

    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 FresherGate
      {    
          int x;     
          float y;     
          public: 
          void GateFunction(int = 0, float = 0.00f, char = 'A'); 
          void GateFunction(float, int = 10.00, char = 'Z'); 
          void GateFunction(char, char, char); 
     }; 
     int main() 
     {    
         FresherGate objGate   
         objGate.GateFunction(10 * 1.0, int(56.0));   
         return 0;
     }
     void FresherGate::GateFunction(int xx, float yy, char zz) 
     {    x = xx + int(yy);  
          cout"x = " void FresherGate::GateFunction(float xx, int yy, char zz) 
     {     
         x = zz + zz;   
         y = xx + yy;    
         cout" x = " 
     void FresherGate::GateFunction(char xx, char yy, char zz)
     {    
          x = xx + yy + zz;   
          y = float(xx * 2);    
          cout" x = " 
    

  20. A.

    The program will print the output x = 65.

    B.

    The program will print the output x = 66.

    C.

    The program will print the output x = 130.

    D.

    The program will print the output x = 180.

    E.

    The program will not compile successfully.

    View Answer

    Workspace

    Discuss Discuss in Forum