Struct pointers are used as function parameters.

Source: Internet
Author: User

Struct pointers are used as function parameters.

 

1 # define _ CRT_SECURE_NO_WARNINGS 2 # include <stdio. h> 3 # include <stdlib. h> 4 # include <string. h> 5 6 // define a struct 7 // define a data type. Alias with fixed memory size, no memory allocated 8/* struct Teacher 9 {10 char name [5]; 11 int age; 12 }; */13 typedef struct Teacher14 {15 char name [64]; 16 int age; 17 int id; 18} Teacher; 19 20 21 struct Student22 {23 char name [64]; 24 int age; 25} s1, s2; // define the type and define the variable 26 27 struct28 {29 char name [64]; 30 int age; 31 32} s3, s4; // anonymous type definition variable 33 34 // three methods for initializing the variable 35 // define the variable and then initialize 36 // 37 Teacher t7 = {"aaaaa", 18, 01 }; // global 38 struct Student239 {40 char name [64]; 41 int age; 42} s5 = {"names", 21 }; 43 44 struct45 {46 char name [64]; 47 int age; 48 49} s6 = {"names", 30}; 50 51 52 void copyTeacher01 (Teacher *, teacher * from) 53 {54 * to = * from; 55} 56 int main () 57 {58 Teacher t1 = {"aaaa", 32, 01}; 59 Teacher t2; 60 t2 = t1; // action taken by the compiler 61 // C compiler provides a simple assignment operation 62 Teacher t3; 63 printf ("t2.name: % s \ n ", t2.name); 64 printf ("t2.age: % d \ n", t2.age); 65 copyTeacher01 (& t3, & t1); 66 printf ("t2.name: % s \ n ", t3.name); 67 printf ("t2.age: % d \ n", t3.age); 68 system ("pause"); 69 return 0; 70}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.