Answer to Question #157629 in C++ for zain ul abdeen

Question #157629

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.


1
Expert's answer
2021-01-27T10:15:37-0500
#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

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS