C language-structure and pointer learning

#include<stdio.h>
#include<string.h>
struct book //define structure type
{
    char name [20];
    short price;
    char author [20];
};
int main ()
{
    struct book b1={"C programming language",55,"Tan Haoqiang"}; Use the structure type to define the structure variable
    struct book* p=&b1; Use the structure type to define the structure pointer to store the address of the structure variable
    strcpy (b1.name ,"C++"); modify the title of the book strcpy----string copy 
    printf ("Book name: %s\n",p->name); pointer -> member
    printf ("作者:%s\n",p->author);
    printf ("price:%d\n",b1.price); structure. member
}

Pointer variables can store addresses, and * is a dereference operator. The definition of complex variables requires the participation of structures.

Guess you like

Origin blog.51cto.com/15126924/2657659