Hi there,
I have read that when we create object of a class, its default constructor is automatically called and default constructor assigns default values to variables e.g. to int it assigns 0 and to float it assigns 0.0 ...
But I have write a program in which I have declare different types of variables and did not assign values to them. When I print their values, it still printing garbage values not default values.
Please anyone tell me why is this happening. I just want to learn the concept of default constructor. The program is as follows. Thanks !
#include <iostream>
using namespace std;
class CheckGarbage
{
private:
int rollNo;
float cgpa;
char* name;
public:
void checkValue()
{
cout<<"Roll no : " <<rollNo <<endl;
cout<<"CGPA : " <<cgpa <<endl;
cout<<"name : " <<name <<endl;
}
};
int main()
{
CheckGarbage c;
c.checkValue();
return 0;
}