04-29-2011, 08:27 AM
Code:
There is no garbage values assign to any variable. Let us consider the following example: #include < iostream.h>
#include < conio.h>
class Student {
private:
char *name;
int age, rollno;
public:
Student(char*name=NULL ,int age=0,int rollno=0) {
cout<< name << endl;
cout<< age << endl;
cout<< rollno << endl << endl;
}
};
int main() {
Student std("Ali",15,10);
// calling overloaded constructor and assigning values to variables, name value is “Ali”, age value is 15, and rollno value is 10
Student std1("Ali",15);
// name value is “Ali”, age value is 15, and rollno value is 0
Student std2("",15,10);
// name value is null, age value is 15, and rollno value is 10
system("pause");
}
