Structure Type

2022. 7. 16. 16:21Coding - 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. 

http://www.tcpschool.com/c/c_struct_intro

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". 

http://www.tcpschool.com/c/c_struct_intro

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. 

http://www.tcpschool.com/c/c_struct_pointer

This is how the memory looks in the array. 

http://www.tcpschool.com/c/c_struct_pointer

 

 

 

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. 

http://www.tcpschool.com/c/c_struct_pointer

'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