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);
If you want record a file with specific information, for example: Imagine that you want save a file with information about students, so, imagine what type information you will need keep in your file, you don't need think a lot to imagine something such as: ID, name, address, phone, email. So the ideal use of a defined data in C is through the structure, you can put your data in your structure type and save at file. For example:
#include <stdio.h>
#include <string.h>
#define LEN_REC 38
struct students {
char id[2],
name[10],
address[15],
phone[10],
end;
};
int main()
{
FILE *p;
char Str1[ LEN_REC + 1 ];
struct students Student[3];
int i;
memcpy( (void*) Student[0].id,"01",2);
memcpy( (void*) Student[0].name,"Marcos Bre",10);
memcpy( (void*) Student[0].address,"Queen Street,50",15);
memcpy( (void*) Student[0].phone,"6409940349",10);
Student[0].end = '\0';
memcpy((void*) Student[1].id,"02",2);
memcpy((void*) Student[1].name,"Peter Berl",10);
memcpy((void*) Student[1].address,"Queen Street,10",15);
memcpy((void*) Student[1].phone,"6409940344",10);
Student[1].end = '\0';
memcpy((void*) Student[2].id,"03",2);
memcpy((void*) Student[2].name,"James Carr",10);
memcpy((void*) Student[2].address,"Queen Street,30",15);
memcpy((void*) Student[2].phone,"6409940344",10);
Student[2].end = '\0';
if((p=fopen("Students.dat","w"))==NULL){
printf("Error: Open file !\n");
exit(0);
}else{
fprintf(p,"%s",(char*) &Student[0] );
fprintf(p,"%s",(char*) &Student[1] );
fprintf(p,"%s",(char*) &Student[2] );
fclose(p);
}
/* to list your Students */
if((p=fopen("Students.dat","r"))==NULL){
printf("Error: Open file !\n");
exit(0);
}else{
/* List the Students from the file */
while( fread( (void*) Str1 ,1, LEN_REC , p )){
Str1[ LEN_REC + 1 ] ='\0';
printf("%s\n", Str1 );
}
fclose(p);
}
return 0;
}
No. C is not an object-oriented language so there's no way to provide a conversion constructor for a user-defined type.
String - is primitive data typestring - is user defined data type
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.
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.
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
In Java, just about anything is defined as a class; a class is a data type, so yes.
String - is primitive data typestring - is user defined data type
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.
user defined
Basic types (primitive data types) have no methods associated with them.
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.
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.
In Java, just about anything is defined as a class; a class is a data type, so yes.
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
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.
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........
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.
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.