C + + Learning Journey-Combat 2-output multi-type variable data using struct struct body

Source: Internet
Author: User

Now the author seems to have become this, I am normal?

Whether it is not normal, start today's coding:

#include <stdio.h>structstudent{intID; Char*Name; intAge ;};//defines a structure that contains student ID, name, age three fields studentintMain () {structStudent mystudent = {1,"Luo Shuai", -};//instantiate a struct and assign a valueprintf"ID value of the mystudent instance variable:%d\n", mystudent.id); printf ("the name value of the mystudent instance variable:%s\n", Mystudent.name); printf ("Age value of mystudent instance variable:%d\n", mystudent.age);//output the individual field values of the instance variable mystudent    return 0;//Exit Program}

Attached:

Description at the end of the article:

1. In a struct, the name field can be declared as char* name or char Name[number] (number indicates the maximum length of the name field);

2, there is about the use of pointers, the author will be a single example to fine-talk, please look forward to!

C + + Learning Journey-Combat 2-output multi-type variable data using struct struct body

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.