37. | What is the output of this program? #include
using namespace std;
class sample
{
int width, height;
public:
void set_values (int, int);
int area () {return (width * height);}
friend sample duplicate (sample);
};
void sample::set_values (int a, int b)
{
width = a;
height = b;
}
sample duplicate (sample rectparam)
{
sample rectres;
rectres.width = rectparam.width * 2;
rectres.height = rectparam.height * 2;
return (rectres);
}
int main ()
{
sample rect, rectb;
rect.set_values (2, 3);
rectb = duplicate (rect);
cout << rectb.area();
return 0;
}
|
|||||||
|
38. | What is the output of this program? #include
using namespace std;
class sample
{
private:
int a, b;
public:
void test()
{
a = 100;
b = 200;
}
friend int compute(sample e1);
};
int compute(sample e1)
{
return int(e1.a + e1.b) - 5;
}
int main()
{
sample e;
e.test();
cout << compute(e);
return 0;
}
|
|||||||
|
39. | What is the output of the following program?
main ( )
{ int x = 2, y = 5;
if (x < y) return (x = x+y); else printf ("z1");
printf("z2");
}
|
|||||||
|
40. | What will be the output of the following code segment, if any? myfunc ( struct test t) {
strcpy(t.s, "world");
}
main( ) {
struct test { char s[10]; } t;
strcpy(t.s, "Hello");
printf("%s", t.s);
myfunc(t);
printf("%s', t.s);
}
|
|||||||
|
41. | If a function is declared as void fn(int *p), then which of the following statements is valid to call function fn? |
|||||||
|
42. | What is the following function computing? Assume a and b are positive integers. int fn( int a, int b) {
if (b == 0)
return b;
else
return (a * fn(a, b - 1));
}
|
|||||||
|
« previous
1
2
3
4
5
6
7
8
9
...next »