C++ Programming - Functions - Discussion
Discussion Forum : Functions - Programs (Q.No. 32)
32.
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;
}
Discussion:
6 comments Page 1 of 1.
Vaibhav said:
6 years ago
The answer is A because of compile-time error.
Honey said:
8 years ago
The correct option is A as the compiler returns error when an object is created with the default constructor for a class with parameterized constructor without default constructor.
Shubham arora said:
1 decade ago
@Sanki.
There are two ways one is either pass the value while creating object, or create object without passing any value but write value in constructor. Example:
First case:
class one
{
one(int a)
{
}};
main()
{
one obj(10);
}
Second case:
class one
{
one(int a=10)
{
}};
main()
{
one obj();
}
Both ways are correct.
There are two ways one is either pass the value while creating object, or create object without passing any value but write value in constructor. Example:
First case:
class one
{
one(int a)
{
}};
main()
{
one obj(10);
}
Second case:
class one
{
one(int a=10)
{
}};
main()
{
one obj();
}
Both ways are correct.
Ankit said:
1 decade ago
If we will declare the default constructor, the compiler will get ambiguity.
Sanki said:
1 decade ago
Just can't get it. Since there is a Parameterized constructor, the default constructor should have been declared. Otherwise, how would the Program compile.
PRAFUL ANAND said:
1 decade ago
At the time of creation of object objBA no value is passed to the constructor. So, arr=NULL, if part will not execute and default value is assigned to the elements of matrix. Display function will print garbage values.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers