Schreibe ein C++ Programm, das Variablen der folgenden Datentypen definiert und sinnvoll…
- User
Schreibe ein C++ Programm, das Variablen der folgenden Datentypen definiert und sinnvoll initialisiert: short, int, unsigned int, long, long long, float, double, long double, bool, char. I Wie viel Byte belegen die jeweiligen Variablen im Speicher? Gebe die Anzahl auf der Kommandozeile aus I Erstelle einen Alias f¨ur die int-Variable. Erstelle einen Zeiger, der auf die Adresse der int Variable zeigt. I Gebe die Adressen der int-Variable, seines Alias und des Zeigers aus. Gebe außerdem den Wert und den dereferenzierten Wert des Zeigers aus.
- Assistant
#include
int main() { short myShort = 10; int myInt = 20; unsigned int myUnsignedInt = 30; long myLong = 40; long long myLongLong = 50; float myFloat = 3.14; double myDouble = 3.1415; long double myLongDouble = 3.141592; bool myBool = true; char myChar = 'A';
int& myIntAlias = myInt; int* myIntPointer = &myInt; std::cout << "Size of short: " << sizeof(myShort) << " bytes" << std::endl; std::cout << "Size of int: " << sizeof(myInt) << " bytes" << std::endl; std::cout << "Size of unsigned int: " << sizeof(myUnsignedInt) << " bytes" << std::endl; std::cout << "Size of long: " << sizeof(myLong) << " bytes" << std::endl; std::cout << "Size of long long: " << sizeof(myLongLong) << " bytes" << std::endl; std::cout << "Size of float: " << sizeof(myFloat) << " bytes" << std::endl; std::cout << "Size of double: " << sizeof(myDouble) << " bytes" << std::endl; std::cout << "Size of long double: " << sizeof(myLongDouble) << " bytes" << std::endl; std::cout << "Size of bool: " << sizeof(myBool) << " bytes" << std::endl; std::cout << "Size of char: " << sizeof(myChar) << " bytes" << std::endl; std::cout << "Address of int variable: " << &myInt << std::endl; std::cout << "Address of int alias: " << &myIntAlias << std::endl; std::cout << "Address stored in int pointer: " << myIntPointer << std::endl; std::cout << "Value of int pointer: " << myIntPointer << std::endl; std::cout << "Dereferenced value of int pointer: " << *myIntPointer << std::endl; return 0;