Function to return sizeof()

So I know how to get the size of a something.

cout << sizeof(char);

However,

I need to write a function that finds the sizeof for these different values that are listed in the main function.

EX.


I need to write a function here.


int main() {

"char";
"int";
"float";
"double;

return 0;
}


Any ideas?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include<iostream>
using namespace std;
void f(){
cout <<"char="<< sizeof(char)<<endl;
cout <<"float="<< sizeof(float)<<endl;
cout <<"int="<< sizeof(int)<<endl;
cout <<"double="<< sizeof(double)<<endl;

}


int main() {
f();
return 0;
}
Thank you, I forgot about using a void function, I was trying to use a function that would get whatever was in main "double", "float", etc... and then get the size and then output.
Topic archived. No new replies allowed.