Created
August 7, 2019 23:19
-
-
Save parzibyte/3200c2ec63c6f287715d20a570d3e5ed to your computer and use it in GitHub Desktop.
Longitud de un arreglo en ANSI C - https://parzibyte.me/blog/2018/09/21/longitud-de-un-arreglo-en-c/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main(int argc, char const *argv[]) | |
{ | |
double arreglo[2] = {123, 456}; | |
// Memoria ocupada por todo el arreglo | |
int tamanioDelArreglo = sizeof(arreglo); | |
// Memoria ocupada por su primer elemento | |
int tamanioDeLaPrimeraVariableDelArreglo = sizeof(arreglo[0]); | |
// División simple | |
int longitud = tamanioDelArreglo / tamanioDeLaPrimeraVariableDelArreglo; | |
printf( "El arreglo ocupa %d bytes.\n" | |
"La primer variable ocupa %d bytes.\n" | |
"Entonces la longitud es: %d", | |
tamanioDelArreglo, tamanioDeLaPrimeraVariableDelArreglo, longitud); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment