Constructors for intrinsic data types

Usually, in C/C++ we initialize variables like this

int roll_no=2235;
float sal=45000.60;

But in C++ we can initialize variables in another way as shown below and this notation of initializing variables is known as a class constructor notation

#include <iostream>
using namespace std;
int main()
{
    int roll_no(2235);
    float sal(45000.60);
    cout << roll_no << endl;
    cout << sal << endl;
    return 0;
}

Output

2235
45000.6

Mohammed Anees

Hey there, welcome to aneescraftsmanship I am Mohammed Anees an independent developer/blogger. I like to share and discuss the craft with others plus the things which I have learned because I believe that through discussion and sharing a new world opens up

Leave a Reply

Your email address will not be published.