What is the size of an int variable and a char variable. What is the size of a variable which points to an int and a variable that points to a char. Now write a piece of code that displays the sizes of the data types mentioned above.
#include <iostream>
int main()
{
int intVariable = 0;
char charVariable = 0;
int* intPointer = &intVariable;
char* charPointer = &charVariable;
std::cout << "Size of an int variable: " << sizeof(intVariable) << " bytes\n";
std::cout << "Size of an char variable: " << sizeof(charVariable) << " bytes\n";
std::cout << "Size of an int pointer: " << sizeof(intPointer) << " bytes\n";
std::cout << "Size of an char pointer: " << sizeof(charPointer) << " bytes\n";
return 0;
}
Resulting output of a 64-bit program:
Size of an int variable: 4 bytes
Size of an char variable: 1 bytes
Size of an int pointer: 8 bytes
Size of an char pointer: 8 bytes
Comments
Leave a comment