Exercise: Functions
Questions for: Functions
What will be the output of the following program?
#include<iostream.h>
struct ExamAdept
{
int arr[5];
public:
void BixFunction(void);
void Display(void);
};
void ExamAdept::Display(void)
{
for(int i = 0; i < 5; i++)
cout<< arr[i] << " " ;
}
void ExamAdept::BixFunction(void)
{
static int i = 0, j = 4;
int tmp = arr[i];
arr[i] = arr[j];
arr[j] = tmp ;
i++;
j--;
if(j != i) BixFunction();
}
int main()
{
ExamAdept objBix = {{ 5, 6, 3, 9, 0 }};
objBix.BixFunction();
objBix.Display();
return 0;
}
A:
0 9 3 6 5
B:
9 3 6 5 0
C:
5 6 3 9 0
D:
5 9 3 6 0
Answer: A
No answer description is available. Let's discuss.
Which of the following statement is correct about the program given below?
#include<iostream.h>
class BixArray
{
int array[3][3];
public:
BixArray(int arr[3][3] = NULL)
{
if(arr != NULL)
for(int i = 0; i < 3; i++)
for(int j = 0; j < 3; j++)
array[i][j] = i+j;
}
void Display(void)
{
for(int i = 0; i < 3; i++)
for(int j = 0; j < 3; j++)
cout<< array[i][j] << " ";
}
};
int main()
{
BixArray objBA;
objBA.Display();
return 0;
}
A:
The program will report error on compilation.
B:
The program will display 9 garbage values.
C:
The program will display NULL 9 times.
D:
The program will display 0 1 2 1 2 3 2 3 4.
Answer: B
No answer description is available. Let's discuss.
Discuss About this Question.
Which of the following statement is correct about the program given below?
#include<iostream.h>
class ExamAdept
{
int x, y, z;
public:
ExamAdept(int x = 100, int y = 30, int z = 0)
{
this->x = x;
this->y = y;
this->z = z;
Display();
}
void Display()
{
cout<< x << " " << y << " " << z;
}
};
int main()
{
int a = 0, b = 1, c = 2;
int &x = ++a;
int &y = --b;
int z = c + b - -c;
ExamAdept objBix(x, y, z);
return 0;
}
A:
The program will print the output 1 0 3.
B:
The program will print the output 1 0 4.
C:
The program will print the output 1 1 3.
D:
The program will print the output 1 1 4.
Answer: B
No answer description is available. Let's discuss.
Discuss About this Question.
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, "ExamAdept");
*txtName = 48;
BixString objTemp(txtName);
cout<< sizeof(txtName);
return 0;
}
A:
Above program will display ExamAdept 8.
B:
Above program will display ExamAdept 9.
C:
Above program will display size of integer.
D:
Above program will display ExamAdept and size of integer.
Answer: B
No answer description is available. Let's discuss.
Discuss About this Question.
What will be the output of the following program?
#include<iostream.h>
#include<string.h>
class ExamAdept
{
char txtMsg[50];
public:
ExamAdept(char *str = NULL)
{
if(str != NULL)
strcpy(txtMsg, str);
}
int BixFunction(char ch);
};
int ExamAdept::BixFunction(char ch)
{
static int i = 0;
if(txtMsg[i++] == ch)
return strlen((txtMsg + i)) - i;
else
return BixFunction(ch);
}
int main()
{
ExamAdept objBix("Welcome to ExamAdept.com!");
cout<< objBix.BixFunction('t');
return 0;
}
A:
6
B:
8
C:
9
D:
15
Answer: A
No answer description is available. Let's discuss.
Discuss About this Question.
Ad Slot (Above Pagination)
Discuss About this Question.