Dados cuatro tipos de variables, a saber, int, char, float y double, la tarea es escribir un programa en C o C++ para encontrar el tamaño de estos cuatro tipos de variables.
C
// C program to find the size of int, char, // float and double data types #include <stdio.h> int main() { int integerType; char charType; float floatType; double doubleType; // Calculate and Print // the size of integer type printf("Size of int is: %ld\n", sizeof(integerType)); // Calculate and Print // the size of charType printf("Size of char is: %ld\n", sizeof(charType)); // Calculate and Print // the size of floatType printf("Size of float is: %ld\n", sizeof(floatType)); // Calculate and Print // the size of doubleType printf("Size of double is: %ld\n", sizeof(doubleType)); return 0; }
C++
// C++ program to find the size of int, char, // float and double data types #include <iostream> using namespace std; int main() { int integerType; char charType; float floatType; double doubleType; // Calculate and Print // the size of integer type cout << "Size of int is: " << sizeof(integerType) <<"\n"; // Calculate and Print // the size of doubleType cout << "Size of char is: " << sizeof(charType) <<"\n"; // Calculate and Print // the size of charType cout << "Size of float is: " << sizeof(floatType) <<"\n"; // Calculate and Print // the size of floatType cout << "Size of double is: " << sizeof(doubleType) <<"\n"; return 0; }
Publicación traducida automáticamente
Artículo escrito por RishabhPrabhu y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA