Vous utiliserez l'opérateur sizeof(type).
Correction
/* Nom : taille.c Auteur : Thierry46 Role : affiche à l'écran la taille en octet des différents types de données du langage C sur votre architecture. Paramètres : non pris en compte. Code retour : 0 (EXIT_SUCCESS) Pour produire un exécutable avec le compilateur libre GCC : gcc -Wall -pedantic -std=c99 -o taille.exe taille.c Pour exécuter, tapez : ./taille.exe Version : 1.2 du 10/3/2008 Licence : GNU GPL */ #include <stdio.h> #include <stdlib.h> #include <limits.h> int main(void) { /* Affiche les tailles récupérées avec sizeof() */ (void)printf("Taille des types en octet :\n" "\t- type char : %zu\n" "\t- type short : %zu\n" "\t- type int : %zu\n" "\t- type long : %zu\n" "\t- type long long : %zu\n" "\t- type float : %zu\n" "\t- type double : %zu\n" "\t- type long double : %zu\n", sizeof(char)*CHAR_BIT/8, sizeof(short)*CHAR_BIT/8, sizeof(int)*CHAR_BIT/8, sizeof(long)*CHAR_BIT/8, sizeof(long long)*CHAR_BIT/8, sizeof(float)*CHAR_BIT/8, sizeof(double)*CHAR_BIT/8, sizeof(long double)*CHAR_BIT/8); return EXIT_SUCCESS; }
Aucun commentaire:
Enregistrer un commentaire