Question 1

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();
}
  • Question 2

    What happens when you attempt to compile and run the following code?
    #include <iostream>
    #include <cstdarg>
    using namespace std;
    int mult(int f, int s, int t);
    int main()
    {
    cout << mult(1,2,3);
    return 0;
    }
    int mult(int f, int s, int t) { int mult_res; mult_res = f*s*t; return mult_res; }
  • Question 3

    What happens when you attempt to compile and run the following code?
    #include <iostream>
    using namespace std;
    int main(int argc, char *argv[]) {
    char *s = "ABCDEF";
    cout << s+2;
    return 0;
    }
  • Question 4

    What happens when you attempt to compile and run the following code?
    #include <iostream>
    #include <sstream>
    #include <string>
    using namespace std;
    int main(void)
    {
    string s;
    s = "Test";
    s.resize (s.size() ? 1);
    cout<<s<<" "<<s.size();
    return 0;
    }
  • Question 5

    Which of the structures is incorrect?
    1:
    struct s1{ int x;
    long int li; };
    2:
    struct s2{ float f; struct s2 *s;
    };
    3:
    struct s3{ float f; struct s3 s;
    };