Skip to content

Instantly share code, notes, and snippets.

@Sarverott
Last active June 14, 2022 14:20
Show Gist options
  • Save Sarverott/707ebb1c6f37f2bee1dbd094ab963900 to your computer and use it in GitHub Desktop.
Save Sarverott/707ebb1c6f37f2bee1dbd094ab963900 to your computer and use it in GitHub Desktop.
prints variable types sizes in var, tab and point variant
#include <iostream>
using namespace std;
template<typename V> void varPrint(char *name, V x, int len){
V xT[len], *xX=xT;
cout
<<name
<<endl
<<"\t variable="<<sizeof(x)
<<" bytes table="<<sizeof(xT)
<<" bytes pointer="<<sizeof(xX)
<<" bytes"
<<endl;
}
int main()
{
cout<<"\n\t---| VARIABLES sizes |---\n\t\t\ttest tables size: ";
int len=0;
cin>>len;
long double ld;
float f;
short s;
int i;
long l;
double d;
char c;
bool b;
varPrint("BOOL", b, len);
varPrint("SHORT", s, len);
varPrint("CHAR", c, len);
varPrint("INT", i, len);
varPrint("FLOAT", f, len);
varPrint("LONG", l, len);
varPrint("DOUBLE", d, len);
varPrint("LONG DOUBLE", ld, len);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment