C++ Programming - Functions
Exercise : Functions - Programs
- Functions - General Questions
- Functions - Programs
26.
What will be the output of the following program?
#include<iostream.h>
class IndiaBix
{
public:
int x, y;
IndiaBix(int xx = 10, int yy = 20)
{
x = xx;
y = yy;
}
void Exchange(int *, int *);
};
int main()
{
IndiaBix objA(30, 40);
IndiaBix objB(50);
objA.Exchange(&objA.x, &objB.y);
cout<< objA.x << " " << objB.y << endl;
return 0;
}
void IndiaBix::Exchange(int *x, int *y)
{
int t;
t = *x;
*x = *y;
*y = t ;
}
27.
Which of the following statement is correct about the program given below?
#include<iostream.h>
class BixArray
{
int Matrix[3][3];
public:
BixArray()
{
for(int i = 0; i<3; i++)
for(int j = 0; j < 3; j++)
Matrix[j][i] = i + j;
}
void Display(void)
{
for(int i = 0; i < 3; i++)
for(int j = 0; j < 3; j++)
cout<< Matrix[j][i] << " ";
}
};
int main()
{
BixArray objBix;
objBix.Display();
return 0;
}
28.
What will be the output of the following program?
#include<iostream.h>
class IndiaBix
{
int x, y, z;
public:
void Apply(int xx = 12, int yy = 21, int zz = 9)
{
x = xx;
y = yy += 10;
z = x -= 2;
}
void Display(void)
{
cout<< x << " " << y << endl;
}
void SetValue(int xx, int yy)
{
Apply(xx, 0, yy);
}
};
int main()
{
IndiaBix *pBix= new IndiaBix;
(*pBix).SetValue(12, 20);
pBix->Display();
delete pBix;
return 0;
}
29.
What will be the output of the following program?
#include<iostream.h>
#include<string.h>
class IndiaBix
{
char txtMsg[50];
public:
IndiaBix(char *str = NULL)
{
if(str != NULL)
strcpy(txtMsg, str);
}
int BixFunction(char ch);
};
int IndiaBix::BixFunction(char ch)
{
static int i = 0;
if(txtMsg[i++] == ch)
return strlen((txtMsg + i)) - i;
else
return BixFunction(ch);
}
int main()
{
IndiaBix objBix("Welcome to IndiaBix.com!");
cout<< objBix.BixFunction('t');
return 0;
}
30.
Which of the following statement is correct about the program given below?
#include<iostream.h>
#include<string.h>
#include<malloc.h>
class BixString
{
char txtName[20];
public:
BixString(char *txtTemp = NULL)
{
if(txtTemp != NULL)
strcpy(txtName, txtTemp);
}
void Display(void)
{
cout<<txtName;
}
};
int main()
{
char *txtName = (char*)malloc(10);
strcpy(txtName, "IndiaBIX");
*txtName = 48;
BixString objTemp(txtName);
cout<< sizeof(txtName);
return 0;
}
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers