Загрузка данных
#include <iostream>
#include <string>
#include <typeinfo>
using namespace std;
typedef unsigned long ul;
typedef long long int lli;
typedef unsigned long long int ulli;
enum Color {Red, Blue, Green};
enum High {Low = 5, Medium = 30};
struct Students
{
char* Name;
int Age;
float Ball;
};
struct Day {
int date;
float id;
};
int main() {
setlocale(LC_ALL, "Russian");
char q;
signed char w;
unsigned char e;
short int r;
unsigned int t;
int y;
long u;
unsigned long i;
long long int o;
unsigned long long int p;
float a;
double s;
long double d;
bool f;
Students g;
cout << "# 1" << "\n";
cout << "Size:" << "\n";
cout << "char:" << sizeof(q) << "\n";
cout << "signed char:" << sizeof(w) << "\n";
cout << "unsigned char:" << sizeof(e) << "\n";
cout << "short int:" <<sizeof(r) << "\n";
cout << "unsigned int:" << sizeof(t) << "\n";
cout << "int:" << sizeof(y) << "\n";
cout << "long:" << sizeof(u) << "\n";
cout << "unsigned long:" << sizeof(i) << "\n";
cout << "long long int:" << sizeof(o) << "\n";
cout << "unsigned long long int:" << sizeof(p) << "\n";
cout << "float:" << sizeof(a) << "\n";
cout << "double:" << sizeof(s) << "\n";
cout << "long double:" << sizeof(d) << "\n";
cout << "bool:" << sizeof(f) << "\n";
cout << "struct:" << sizeof(g) << "\n";
cout << "# 2"<< "\n";
ul s1 = 100;
lli s2 = 15645646546;
ulli s3 = 12;
cout << "ul" << s1 << "\n";
cout << "lli" << s2 << "\n";
cout << "ulli" << s3 << "\n";
cout << "# 3" << "\n";
Color c1; // Переменная без инициализации
Color c2 = Green; // Переменная с инициализацией
High h = Medium;
c1 = Red;
if (c1 < c2) {
cout << "True: c1 < c2 (Red(0)<Green(2)" << "\n";
} else
cout << "False: c1 < c2 (Red(0)<Green(2)" << "\n";
int calc = Red + 5; // 0+5=5
int diff = Low - Green; //5-2=3
cout << "Red + 5 = " << calc << "\n";
cout << "Low - Green = " << diff << "\n";
cout << "sizeof(c1):" << sizeof(c1) << "\n";
cout << "enum(None):" << sizeof(Color) << "\n";
cout << "enum:" << sizeof(High) << "\n";
cout << "# 4" << "\n";
cout << "Размеры базовых типов\n";
cout << "sizeof(char*) = " << sizeof(char*) << " байт\n";
cout << "sizeof(int) = " << sizeof(int) << " байт\n";
cout << "sizeof(float) = " << sizeof(float) << " байт\n\n";
cout << "Размеры полей структуры\n";
cout << "sizeof(g.Name) = " << sizeof(g.Name) << " байт (указатель)\n";
cout << "sizeof(g.Age) = " << sizeof(g.Age) << " байт\n";
cout << "sizeof(g.Ball) = " << sizeof(g.Ball) << " байт\n\n";
size_t sum_fields = sizeof(g.Name) + sizeof(g.Age) + sizeof(g.Ball);
cout << "Сумма размеров полей = " << sum_fields << " байт\n";
cout << "sizeof(Students) = " << sizeof(Students) << " байт\n";
cout << "# 5" << "\n";
int intVal = 1000;
float floatVal = 3.14159;
double doubleVal = 999999999.9;
// Явное преобразование
int fromFloat = static_cast<int>(floatVal);
float fromInt = static_cast<float>(intVal);
cout << "float -> int (потеря дробной части): " << fromFloat << "\n";
cout << "int -> float: " << fromInt << "\n";
// Неявное преобразование в выражении
double result = intVal + floatVal;
cout << "Неявное приведение в выражении int + float -> double: " << result << "\n";
// Потенциальная потеря точности
unsigned long long bigNum = 1000000000000;
int smallCast = static_cast<int>(bigNum);
cout << "Понижающее преобразование большого числа: " << smallCast << " (возможна потеря данных)\n";
cout << "# 6" << "\n";
cout << "typeid(intVal).name(): " << typeid(intVal).name() << "\n";
cout << "typeid(floatVal).name(): " << typeid(floatVal).name() << "\n";
cout << "typeid(result).name(): " << typeid(result).name() << "\n";
cout << "typeid(2 + 3.4).name(): " << typeid(2 + 3.4).name() << "\n";
}