struct use notes in C + + _c language

Source: Internet
Author: User

1.c++ structure variables can be omitted in the declaration of struct, in C this is not possible, examples are as follows

#include <iostream>
#include <string>
using namespace std;

struct test{
  int num;
  string name;
};

int main (void)
{
  Test T;
  T.num=1;
  T.name= "Jack";
  cout<<t.num<< "" <<t.name<<endl;    
}

The 2.c++ struct declaration can be declared in the main () function, it is also possible to invoke the entire program before the main () function, which is also the most commonly used, and, internally, only within a function, that is, the concept of a local variable that can be used within a declared function. As follows

int main (void)
{
  struct test{
    int num;
  };
  
  Test Hello;//right
  
}

void T ()
{
  Test T;//wrong
}

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.