2022. 7. 16. 16:21ㆍCoding - C
Structure Type: A data type which the user can make on thir own using the basic data types such as int, char, bool. They can show the complex structure that can't be shown just using basic data types. While array is a list of the same data type, structure type is many basic data types formed into one new data type. The variables in structure types are called member or member variable.
We use the keyword "struct" to make a new data type, in form of
struct typename
{
var1type var1name
var2type var2name
}
In this case, the new data type is "book", which contains char title, char author, and int price.
typedef struct: We use this for giving the already existing data type a new name. The basic form is typedef struct structname structNEWname.
In this case, the new name of this data type is "TEXTBOOK", which was formerly "book".
Struct can also be used for arrays, as like this example, the variable made is called "text_book" with length of 3. Using the formerly made "book", we can use .title to show the names of the books.
This is how the memory looks in the array.
Structs can also be used for pointers. in form of struct typename * typepointername. We can use either arrows (-->) or asterisks (*). Make sure that we use amperstands (&) to show the address, like the examppel below.
'Coding - C' 카테고리의 다른 글
Character and Strings (0) | 2022.07.09 |
---|---|
Memory Management (0) | 2022.07.08 |
Pointers and Arrays (0) | 2022.07.02 |
Pointers (0) | 2022.07.02 |
Practice Problem Part 2 & Practice Problem #2 (0) | 2022.06.25 |