C++: some simple pointer arithmetic

What will be the output of the following code:

char *mychar; //points to memory location 1000
short *myshort; //points to memory location 2000
long *mylong //points to memory location 3000
cout << mychar << myshort << mylong;

Correct answer is:
1001 2002 3004
Because of the following table:
char : 1 byte
short : 2 bytes
int : 4 bytes
long : 4 bytes
float : 4 bytes
double : 8 bytes

This entry was posted in C++, Interview, Programming and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s