c语言i––是什么_C语言中的结构–第3部分

c语言i––是什么

Read: Structure in C – Part 2

In the last two tutorials I gave a brief overview and functions of structures in C programming. Structure is one of the most important topic of C programming. The concept of structure is re-modified to make the object oriented language C++. Today I will tell you about the various advance features of structures in C programming. I will also tell you about the uses of structures at the end of this tutorial. So lets get started.

Structure in C

1. C language gave user the power to create your own variables. Structures are generally used to create user defined data types. To make the functionality of structures similar to other variables, the elements of structures are stored in contiguous memory locations. Due to this, one can easily assign all the values of one structure variable to other structure variable.

Remember we can also do piece meal copy by copying every element of structure one by one. Lets make one program to understand this.


Output

Structure in C - Part 3

2. Nesting is one main feature in C which gives the flexibility to create complex programs. Structures can also be nested to create some complex structures. Generally programmers prefer to stay within 3 layers of nesting. But remember practically there is no limit of nesting in C. Consider the below program to understand this.


Output

Structure in C - Part 3

Explanation
Nesting of structure is quite simple. Consider carefully the two dot operators I have used inside printf function to access the elements of first structure.

3. So far I told you about the pointer to integer, pointer to character, pointer to array and so on. Similar to this we can also make pointer to a structure. It is used to store the address of a structure. Remember we cannot use (.) dot operator to access the structure elements using structure pointer. We have to use arrow operator (->) for that purpose. Consider the below code.

Output

Structure in C - Part 3

Explanation
Consider carefully I have used arrow operator to access elements at that address

Uses of Structure in C

Structures are generally used to maintain databases in some organisation. One separate concept of Data Structures is also made to maintain the databases using structures. Apart from this some very common uses are given below.

a) Formatting a floppy
b) Receiving a key from the keyboard
c) Moving the cursor on the display
d) Making small games like Tic Tac Toe
e) Sending the output to printer

翻译自: https://www.thecrazyprogrammer.com/2015/02/structure-in-c-part-3.html

c语言i––是什么

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值