Answer to Question #157608 in C++ for Usama Saleem

Question #157608

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-24T11:10:00-0500

Size of an int variable is 4 bytes. Size of a char variable is 1 byte. Size of variable which points to an int and a variable that points to a char are the same and it is 8 bytes.

#include <iostream>
using namespace std;


int main()
{
    int a = 3;
    char b = 's';
    int* p = &a;
    char* p1 = &b;
    cout << "Size of an int variable: " <<sizeof(a) << " bytes.\n";
    cout << "Size of a char variable: " << sizeof(b) << " bytes.\n";
    cout << "Size of a variable that points to int: "<< sizeof(p) << " bytes.\n";
    cout <<"Size of a variable that points to char: "<< sizeof(p1) << " bytes.\n";
}

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