Answer the question
In order to leave comments, you need to log in
How to create your own data type in C language?
I asked this question yesterday but unfortunately I was never given the right answer, but most likely it was I who did not clearly explain the problem. The fact is that in the C language there is no concept of a string being an array of characters. How to create a string data type. Help I'm newbie. I learned about typedef char* string, but I don’t understand it, explain how to create a data type string (string) in C. The string.h library does not have a string data type because I tried to write string s = "Hello World".
compiled gcc -std=gnu99 hello.c gave an error that the string data type was not recognized although string.h was included.
PS I apologize for the grammatical errors in the text.
Answer the question
In order to leave comments, you need to log in
The standard mechanism for defining a new type in C is struct some{ ... }, union some{ ... }, enum some {...}. It is better to read more in the standard or at https://en.cppreference.com/.Also the type declaration is a pointer to an object of type type - type* type_name; or a pointer to a pointer of an object of type type - type*** type_name; etc. , function pointer void(func*)(int, int), array of objects of type some[num], (both with arrays and with pointers, different dimensions of array type are possible, i.e. two-dimensional) but with function pointers, and in the general and conversion of a name to a pointer and conversion of arrays to pointers, etc. should be treated carefully. In general, such subtleties are already a level for serious writing firewood or axes, so I advise you to stock up on the standard, as the type system is seriously different from that in c ++ (I just warn you in advance). Also, typedef struct {...} some is a useful C language idea for creating an alice type on an anonymous structure (yes there are anonymous structures and other data types), often useful in combination with the gcc extension for nested functions for use in scope in place. For a deeper understanding, bitfields can also be useful, often in place with alignment used for typing puns in serializers and pseudo-inheritance implementations, Berkeley sockets being the canonical example. I forgot to mention some type modifiers such as long long etc. also essentially use a reserved fundamental typehttps://stackoverflow.com/questions/35401017/is-lo... .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question