I have simple program
struct Node
{
int data;
Node *next;
};
int main()
{
// Make linked list with 10 Node
Node* head = new Node();
head->data = 9;
Node* link = head;
for (int i = 0 ; i < 9 ; ++i)
{
Node* newNode = new Node();
newNode->data = i;
link->next = newNode;
link = newNode;
}
printListAddress(head);
// Make array of 10 Node
Node* arr= new Node[10];
printArrAddress(arr, 10);
return 0;
}
And i get
0x1f97c20 0x1f97c40 0x1f97c60 0x1f97c80 0x1f97ca0
0x1f980d0 0x1f980e0 0x1f980f0 0x1f98100 0x1f98110
In linked list, difference of memory address of each node is 20 and in array is 10 but sizeof(arr[i]) = sizeof(*head) =16. Please explain me the difference. Thanks for all help;
sizeof(Node).sizeof(Node)is, the compiler can pad it up to a size it sees fit.