Question 71

Point out an error in the program.
#include <iostream>
using namespace std;
int main()
{
char s1[] = "Hello";
char s2[] = "world";
char *const ptr = s1;
*ptr = 'a';
ptr = s2;
return 0;
}
  • Question 72

    What will happen when you attempt to compile and run the following code?
    #include <iostream>
    using namespace std;
    int getValue();
    int main()
    {
    const int x = getValue();
    cout<<x;
    return 0;
    }
    int getValue()
    {
    return 5;
    }
  • Question 73

    What happens when you attempt to compile and run the following code?
    #include <iostream>
    using namespace std;
    class A
    {
    public:
    void Print(){ cout<<"A";}
    };
    class B:public A
    {
    public:
    virtual void Print(){ cout<< "B";}
    };
    int main()
    {
    A *obj;
    A ob1;
    obj = &ob1;
    obj?>Print();
    B ob2;
    obj = &ob2;
    obj?>Print();
    }
  • Question 74

    What happens when you attempt to compile and run the following code?
    #include <iostream>
    using namespace std;
    int main(){
    int i = 1;
    if (i==1) {
    cout << i;
    } else {
    cout << i-1;
    }
    return 0;
    }
  • Question 75

    What is the output of the program if characters 'h', 'e', 'l', 'l' , 'o' and enter are supplied as input?
    #include <iostream> #include <string>
    using namespace std;
    void f();
    int main()
    {
    f();
    return 0;
    }
    void f()
    {
    char c;
    c = cin.get();
    cout << c;
    if(c != '\n')
    f();
    }