answersLogoWhite

0

Yes, but it cannot be done in C as intuitively as it can be done in C++:

struct X {

X (const int i): m {i} {} // converts an int to an X [C++ only]

X& operator= (const int i) { m=i; return *this; } // assign an int to an X [C++ only]

int m;

};

Usage:

X x {42}; // construct X from int

x = 0; // assign an int to an X

In C we must use a conversion function:

struct X convert (const int i) { // convert an int to an X

struct X;

x.m = i;

return x;

}

Usage:

struct X x;

x = convert (42);

User Avatar

Wiki User

8y ago

What else can I help you with?

Continue Learning about Engineering
Related Questions

Is string is primitive or user defined data type?

String - is primitive data typestring - is user defined data type


Which data type can store any data?

There is no such data type. However, when we use user-defined data types of our own type, then that type of data can be stored in a variable. So as a term, you may say that user-defined data type can store any data. As the data-type used in any variable will be depending upon us.


What is data type of class in oops?

user defined


What is the difference between class data type and basic type in c plus plus .How can someone know which one is class type and which one is basic type.?

Basic types (primitive data types) have no methods associated with them.


What is the need for operator overloading?

1. Most fundamental data types have pre-defined operators associated with them. For example, the C++ data type int, together with the operators +, -, *, and /, provides an implementation of the mathematical concepts of an integer. To make a user-defined data type as natural as a fundamental data type, the user-defined data type must be associated with the appropriate set of operators. 2. Increases user readabitily.


Difference between built in data type and user-defined datatype?

A built in data type is a framework's native data type. By default you'd probably have some built in generic data types, such as integer, string, boolean and so on. In the other hand sometimes you can extend the framework's data types, by programminga user-defined data type. In this data type you have to define it's behaviour and structure, and once defined, you can use it the same way you use the default data types. In PostgreSQL or Oracle, you can define data types. You can read about it on their webs.


Is button a data type in Java?

In Java, just about anything is defined as a class; a class is a data type, so yes.


What are the basic data type and subtype used by C compiler .explain properly?

Basically data types are divided into three types namely, 1. primary data type -> this is sub divide into int, float, char, void. 2. derived data type -> this is sub divide into array, pointer. 3. user defined data type -> this is sub divide into struct, union, enum, typedef. by, k.p.sruthi


What are user defined data types?

Actually user defined data type made by user like array,structure,union,pointer. the data type which is define by user or programer according to his need is called user define data type and also called the programer define data type........


What is categorical data?

Categorical data is the statistical data type consisting of categorical variables or of data that has been converted into that form, for example as grouped data.


Application of array in data structure?

That rather depends on the underlying type. For any given type T, an array of type T is user-defined if T is user-defined, otherwise it is built-in. For example: #include<string> // required to use std::string std::string s[42]; // user-defined array int i[42]; // built-in array Here, s is a user-defined array because std::string is a user-defined type, whereas i is a built-in array because int is a built-in type.


What is the default data type for Visual Basic?

A variable has a data type such as integer, string, double. A data type tells the variable to only store values that are a particular data type, so you can only store numbers without decimal points in an integer variable, and only characters such as "ABCD" in a string variable.