The struct in C is a value type, and when a struct is assigned to another struct, the value is passed

Source: Internet
Author: User

#include <stdio.h>intMain () {structPerson {intAge ;            }; structPerson P1 = { +}; //value is passed, assigning the value of all member variables in the P1 to the corresponding member variable in the P2    structPerson p2=P1; //changes the value of the member variable of the P1 without affecting the value of the corresponding member variable in the P2P1.age = -; printf ("p1.age=%d\n", P1.age); printf ("p2.age=%d\n", P2.age); return 0;}

Results:

The struct in C is a value type, and when a struct is assigned to another struct, the value is passed

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.