[C ++] initialize struct value assignment struct output struct members

Source: Internet
Author: User

/** Copyright and version statement of the program: * Copyright (c) 2012, Emy of computer science, Yantai University * All rights reserved. * file name :. cpp * Author: Mao Tong * Completion Date: July 15, January 22, 2013 * version number: v1.0 * description of the task and solution section: * input description: no */[cpp]/* defines two struct variables: student1 and student2. The members include the student ID, name, gender, birth date, and score. student2 is initialized, then, the value of student2 is assigned to student1. Output student1 members */# include <iostream> using namespace std; struct Date // declare struct type Date {int month; int day; int year ;}; struct Student {int num; char name [20]; char sex; Date birthday; // declare that birthday is a member of the Date type float score;} student1, student2 = {10002, "wangli", 'F', 1992, 89.5,}; // defines student1, student2, and initializes int main () {student1 = student2; // assign the values of student2 members to the cout <student1.num <endl; // output the cout value of the num member in student1 <student1.name <endl; // cout <student1.sex <endl; // cout <student1.birthday <endl; // error cout <student1.birthday. month <'/' <student1.birthday. day <'/' <student1.birthday. year <endl; // output the cout value of each birthday member in student1 <student1.score <endl; return 0 ;}/ * running result: Experience: knowledge point summary :*/

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.