Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Let's look at the datatypes an binary basic-types.cpp

The content of this file can be read here

Code Block
languagecpp
titleCode Sample
linenumberstrue
collapsetrue
// basic-types.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include "pch.h"
#include <iostream>
#include <bitset>
#include <string.h>
#include <stdlib.h>

using namespace  std;

template<typename T>
void	printBinaryValue(T value)
{
	cout << "sizeof value: " << sizeof(value) << endl;
	char* bits = reinterpret_cast<char*>(&value);
	for (int n = sizeof(value) - 1; n > -1; --n)
		std::cout << std::bitset<8>(bits[n]) << endl;

	for (int n = sizeof(value) - 1; n > -1; --n)
		std::cout << std::bitset<8>(bits[n]);
	std::cout << '\n';
}


void	dataTypeSizes()
{
	cout << sizeof(bool) << endl;
	cout << sizeof(char) << endl;
	cout << sizeof(int) << endl;
	cout << sizeof(double) << endl;
}

void	fooBar()
{
	int x = 99;

	{
		int x = 33;
		int y = x;
	}
}

int main()
{
	int x = 55;
	int hex = 0x11;
	float f1 = 55e-0;
	float f2 = 55e-1;
	float f3 = 55e+1;

	cout << "integer of " << x << endl;
	printBinaryValue(x);

	cout << "hex of " << hex << endl;
	printBinaryValue(hex);

	cout << "float of 55e-0" << endl;
	printBinaryValue(f1);

	cout << "float of 55e-1" << endl;
	printBinaryValue(f2);

	cout << "float of 55e+1" << endl;
	printBinaryValue(f3);

	fooBar();

	dataTypeSizes();
}