• # En C

    Posté par . En réponse au message les structures en c. Évalué à 5. Dernière modification le 15 janvier 2020 à 13:13.

    En C :

    Dans le premier cas, on définit une structure anonyme et on définit un type : etudiant qui est un alias de la structure.

    typedef struct {
     char nom[10];
    }
    etudiant;
    

    Dans le reste du programme, on peut utiliser etudiant directement.

    Par ex:

    etudiant bob;
    strcpy(bob.nom, "bob");
    printf("le nom est %s\n", bob.nom);
    

    Dans le second cas, on ne crée pas de type, et on dit utiliser struct etudiant dans le code:

    struct etudiant{
     char nom[10];
    };
    
    struct etudiant bob;
    strcpy(bob.nom, "bob");
    printf("le nom est %s\n", bob.nom);