Single Structure Declaration

In case it is necessary to define structure variables only once, it is not necessary to define a structure type. The structure can be declared and subsequently the variables’ names can be typed, followed by a semicolon:
// definition of a single pupil structure, not of a type
struct
{
    char name[20];
    int gradesArray[10];
    Pupil *pStudyingMate;
} pupil;
Further, even in case a structure type is needed, structure variables can be declared right after the structure:
struct MyStruct
{
    int field1;
    float field2
} structVar1, structVar2;


Example


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

struct MyStruct // MyStruct can be used to declare other structure variables
{
     int field1;
     float field2;
} structVar1, structVar2; // declaration of two structure variables

int main()
{
     MyStruct anotherMyStructVar;

     struct
     {
           char name[20];
           int gradesArray[10];
     } pupil; // definition of a single pupil structure, not of a type

     // structures initialization
     strcpy(pupil.name, "Jake");

}