zoukankan      html  css  js  c++  java
  • structures in c

    c语言结构体,以前没仔细看,原来对其理解不够。

    C++语言: Codee#25801
    01 #include <stdio.h>
    02
    03 struct point
    04 {
    05     int x;
    06     int y;
    07     float unknown;
    08 };
    09
    10 struct rect
    11 {
    12     struct point pt1;
    13     struct point pt2;
    14 };
    15
    16 struct point makepoint(int x, int y)
    17 {
    18     struct point temp;
    19
    20     temp.x = x;
    21     temp.y = y;
    22     return temp;
    23 }
    24
    25 struct point addpoint(struct point p1,
    26                       struct point p2)
    27 {
    28     p1.x += p2.x;
    29     p1.y += p2.y;
    30
    31     return p1;
    32 }
    33
    34 int main()
    35 {
    36     /*
    37     the only legal operations on a structure are copying it
    38     or assigning to it as a unit ,
    39     taking its addresss with & ,and accessing its member
    40     */
    41     struct point pt = makepoint(9, 9);
    42     struct point pt1 = {1, 1};
    43     struct point ans = addpoint(pt, pt1); // attention
    44     struct point test = ans;                // attention
    45
    46     printf("%d %d\n", test.x, test.y);
    47
    48     return 0;
    49 }
  • 相关阅读:
    Session
    python内存优化机制中的小秘密
    跨域请求
    Cookie
    json
    Python深浅拷贝辨析
    Django form组件相关
    Python 中的 if __name__ == '__main__'
    online_judge_1108
    online_judge_1107
  • 原文地址:https://www.cnblogs.com/invisible/p/2393293.html
Copyright © 2011-2022 走看看