Please excuse me if this is a repeated question
This is my code
#include "stdafx.h"
#include <stdio.h>
#include "iostream"
#include <stdlib.h>
using namespace std;
int main()
{
char * name = "Hello";
cout << "2" << endl;
cout << "Address2 is " << &name << " value at address is " << * (&name) << endl;
cout << "Next address2 is " << &name + 1 << " value at address is " << name + 1 << " " << sizeof(char) << endl;
cout << "3" << endl;
cout << "Address3 is " << &name << " value at address is " << name << endl;
cout << "Next address3 is " << &name + sizeof name << " value at address is " << name + sizeof name << endl;
getchar();
}
and this is the output
Address2 is 003EFAA4 value at address is Hello // easy for me to understand
Next Address2 is 003EFAA8 (This is where i struggle to understand. My understanding is the next address should be 003EFAA5 considering char is of 1 Byte?
output same as 1
Next Address2 is 003EFAB4 (This is where i struggle to understand too. My understanding is the next address should be 003EFAA8 when address of variable name is 003EFAA4 considering size of char pointer is of 4 Byte?
My understanding about memory is the addresses are referenced in terms of bytes. If that is true then why in number 3 above it gives me the address which is 4 bytes further and in number 4 above it gives me the next address that is 10 bytes further?
Any explanation would be highly appreciated. Thank you