Reputation:
I am trying to figure out how much my structure will take memory consumption.Consider the following code
struct tNode{
short data;
tnode *left;
tnode *right;
tnode *student;
}
so i know data
is 2 bytes but what about *left
,*right
and *student
,how much memory will they consume and how to calculate it.
Upvotes: 0
Views: 682
Reputation: 29985
You're looking for the sizeof operator
Returns size in bytes of the object representation of type
Example usage:
#include <iostream>
class tnode;
struct tNode {
short data;
tnode *left;
tnode *right;
tnode *student;
};
int main()
{
std::cout << sizeof(tNode) << std::endl;
return 0;
}
Output on my machine:
32
Upvotes: 1