[ create a new paste ] login | about

Link: http://codepad.org/KepUXN40    [ raw code | output | fork ]

C++, pasted on Jun 22:
#include <iostream>
using namespace std;

template <typename T>
int mysizeof(T)
{
  T temp1;
  T temp2;

  return (int)&temp1 - (int)&temp2;
}

int main()
{
  cout << "sizeof mysizeof" << endl;

  char c = 0; short s = 0; int i = 0; long l = 0;
  float f = 0; double d = 0; long double ld = 0;

  cout << "char: " << mysizeof(c) << endl;
  cout << "short: " << mysizeof(s) << endl;
  cout << "int: " << mysizeof(i) << endl;
  cout << "long: " << mysizeof(l) << endl;
  cout << "float: " << mysizeof(f) << endl;
  cout << "double: " << mysizeof(d) << endl;
  cout << "long double: " << mysizeof(ld) << endl;
}


Output:
1
2
3
4
5
6
7
8
sizeof mysizeof
char: 1
short: 2
int: 4
long: 4
float: 4
double: 8
long double: 16


Create a new paste based on this one


Comments: