A
arnuld
------------- PROGRAMME -----------
/* Stroustrup, 5.9, exercise 2
STATEMENT:
what on your system, ar ethe restrictions on the types
char*, int* and voic*?
e.g. may an int* have an odd value? HINT: alignment
SOLUTION:
we will solve this problem by looking at the addresses .i.e
we will print pointers directly. since by default HEX notation
is used, we will use "std::dec" to convert the addresses to DEC
*/
#include<iostream>
int main()
{
int i = 0;
int j = 1;
int k = 2;
char a = 'a';
char b = 'b';
char c = 'c';
int* pi = &i;
int* pj = &j;
int* pk = &k;
char* pa = &a;
char* pb = &b;
char* pc = &c;
void* pv1 = pi;
void* pv2 = pb;
void* pv3 = pj;
std::cout << std::dec
<< "pi = " << pi << '\n'
<< "pj = " << pj << '\n'
<< "pk = " << pk << '\n'
<< '\n'
<< "pa = " << pa << '\n'
<< "pb = " << pb << '\n'
<< "pc = " << pc << '\n'
<< '\n'
<< "pv1 = " << pv1 << '\n'
<< "pv2 = " << pv2 << '\n'
<< "pv3 = " << pv3 << '\n'
<< std::endl;
return 0;
}
---------- OUTPUT -----------------
[arch@voodo tc++pl]$ g++ 5.9_ex-02.cpp
[arch@voodo tc++pl]$ ./a.out
pi = 0xbff81d9c
pj = 0xbff81d98
pk = 0xbff81d94
pa = a
pb = ba
pc = cba
pv1 = 0xbff81d9c
pv2 = 0xbff81d92
pv3 = 0xbff81d98
[arch@voodo tc++pl]$
--------------------------------------
i do not understand these 2 things:
1.) why it did not print the address of CHAR pointers ?
2.) why i did not get DEC representation ?
/* Stroustrup, 5.9, exercise 2
STATEMENT:
what on your system, ar ethe restrictions on the types
char*, int* and voic*?
e.g. may an int* have an odd value? HINT: alignment
SOLUTION:
we will solve this problem by looking at the addresses .i.e
we will print pointers directly. since by default HEX notation
is used, we will use "std::dec" to convert the addresses to DEC
*/
#include<iostream>
int main()
{
int i = 0;
int j = 1;
int k = 2;
char a = 'a';
char b = 'b';
char c = 'c';
int* pi = &i;
int* pj = &j;
int* pk = &k;
char* pa = &a;
char* pb = &b;
char* pc = &c;
void* pv1 = pi;
void* pv2 = pb;
void* pv3 = pj;
std::cout << std::dec
<< "pi = " << pi << '\n'
<< "pj = " << pj << '\n'
<< "pk = " << pk << '\n'
<< '\n'
<< "pa = " << pa << '\n'
<< "pb = " << pb << '\n'
<< "pc = " << pc << '\n'
<< '\n'
<< "pv1 = " << pv1 << '\n'
<< "pv2 = " << pv2 << '\n'
<< "pv3 = " << pv3 << '\n'
<< std::endl;
return 0;
}
---------- OUTPUT -----------------
[arch@voodo tc++pl]$ g++ 5.9_ex-02.cpp
[arch@voodo tc++pl]$ ./a.out
pi = 0xbff81d9c
pj = 0xbff81d98
pk = 0xbff81d94
pa = a
pb = ba
pc = cba
pv1 = 0xbff81d9c
pv2 = 0xbff81d92
pv3 = 0xbff81d98
[arch@voodo tc++pl]$
--------------------------------------
i do not understand these 2 things:
1.) why it did not print the address of CHAR pointers ?
2.) why i did not get DEC representation ?