zoukankan      html  css  js  c++  java
  • 结构体

    #include<iostream>
    #include<cstring>
    using namespace std;
    typedef struct books{
    char title[14];
    char writer[14];
    
    } books;
    //void printbook(struct books *b);
    void showbook(books *b){ //这里声明的同时定义函数体
    cout<<b->title;
    cout<<b->writer;//访问结构体指针执行的结构体的成员变量需要使用指向箭头
    
    }
    int main(){
    
    books b1;
    strcpy(b1.title,"hello");
    strcpy(b1.writer,"webcyh");
    showbook(&b1);
    
    return 0;
    }
    ~
    "16.cpp" 23L, 324C written
    [root@VM_0_11_centos gcc]# g++ 16.cpp -o 16.c
    [root@VM_0_11_centos gcc]# ./16.c
    hellowebcyh[root@VM_0_11_centos gcc]# 
    

      

    您可以在上述定义的指针变量中存储结构变量的地址。为了查找结构变量的地址,请把 & 运算符放在结构名称的前面,如下所示:

    struct_pointer = &Book1;

    为了使用指向该结构的指针访问结构的成员,您必须使用 -> 运算符,如下所示:

    struct_pointer->title;
  • 相关阅读:
    tftp服务、串口工具minicom
    意外的“黄金点”
    软件工程实践总结
    关于 K米 —— 的案例分析
    关于git的学习
    第二次作业_需求分析与原型设计
    安装appium
    淘宝
    Selenium API基础 8种定位
    selenium
  • 原文地址:https://www.cnblogs.com/webcyh/p/11268085.html
Copyright © 2011-2022 走看看