user4836681
user4836681

Reputation:

finding out memory consumption of a structure

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

Answers (1)

Aykhan Hagverdili
Aykhan Hagverdili

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

Related Questions