C/C++: Exemple d’utilisation d’union

Author:


{filelink=13950}

#include 
#include 

//Création d'une union
union demo_struct
 {
  int ID;
  char nom[80];

} etudiant;

int main(void)
{

	//Accéder aux Membres de l'union
	int etat=1;
	etudiant.ID=12;

	printf("ID= %d, Nom: %sn", etudiant.ID, etudiant.nom);

	etat=2;
	strcpy(etudiant.nom, "Sakoba");

 printf("ID= %d, Nom: %sn", etudiant.ID, etudiant.nom);

 return 0;
}

Leave a Reply

Your email address will not be published. Required fields are marked *