C Language - Functions

You Are Here :: Home > C Language > Functions - General Questions

 
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;
}

A. 20 B. 16
C. 24 D. None of the mentioned




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;
}

A. 100 B. 200
C. 300 D. 295




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");
}

A. z2 B. z1z2
C. Compilation error D. None of these




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);
}

A. Hello Hello B. world world
C. Hello world D. the program will not compile




41.

If a function is declared as void fn(int *p), then which of the following statements is valid to call function fn?

A. fn(x) where x is defined as int x; B. fn(x) where x is defined as int *x;
C. fn(&x) where x is defined as int *x; D. fn(*x) where x is defined as int *x;




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));
}

A. Output will be 0 always B. Output will always be b
C. Computing ab D. Computing a + b




« previous

1

2

3

4

5

6

7

8

9

...

next »

 
 
 



© 2013 freshersindia.in ® | Copyrights | Terms & Conditions
   Designed by Freshers India
Catch Us on