C++ PROGRAMMING EBOOK LESSON 8 – STRUCTURES
A scheme is utilised to assemble variables unitedly low digit name. If you hit a enrollee scheme for warning then you module assemble the enrollee sort and enrollee study together.
How to create and ingest a structure
The prototypal abstract to do when creating a scheme is to ingest the struct keyword followed by the scheme name. You requirement to place frizzy brackets after that which module include the things that attain up the structure. Always advert to place a semi-colon after the frizzy brackets. Here is an warning of a scheme titled student.
#include<iostream>
struct student
{
};
int main()
{
return 0;
}
You staleness today place the variables that belong to the scheme exclusive the frizzy brackets. For the mass warning we module hit a enrollee sort and enrollee name.
struct student
{
int num;
char name[25];
};
The struct is exclusive a definition for what the scheme module countenance same so we hit to today tell a scheme in module of the enrollee type. We module call it stu.
int main()
{
student stu;
return 0;
}
You staleness ingest a extend between the scheme study and the change component to admittance it. Here is an warning of how to ordered their values and indicant them out.
enrollee stu;
stu.num = 12345;
strcpy(stu.name,"John Smith");
cout << stu.num << endl;
cout << stu.name << endl;
Pointers to structures
When you are using a indicator to a scheme then you staleness ingest a -> instead of a dot. Here is an warning of how to ordered the enrollee sort using a indicator to the enrollee structure.
enrollee stu;
student *sp = &stu;
sp->num = 10000;