can't google char pointers!!!

Hello!
Pleas, I can't google the answer, how to get NORMAL addres in char pointer!!!
I tried in codepad and in ideone, please delete if the page accepts my last 2 trials, cause I do not see them right now (it said error) .


Please have a look at the output in ideone, it is even mroe interesting!!!
Many thanks!!!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
  #include<iostream>
using namespace std;

int main(){

char * pletter;

char letter1='b';
cout<<"letter1: "<<letter1<<endl<<endl;
pletter=&letter1;
cout<<"pletter: "<<pletter<<endl;
cout<<"*pletter: "<<*pletter<<endl;
cout<<"&letter1: "<<&letter1<<endl;
std::cout<<&letter1<<std::endl;


return 0;

}
if you just want the address you can cast the char* to a void* and output that. If you just want the dereferenced character your *pletter is the correct choice.

std::cout << (void*)&myCharVar;
To expand on the previous answer, C++ provides a special case overload for const char * to provide compatability with C-style strings.

As suggested, cast to a (void *) if you want the raw pointer.
Hello!
MANY THANKS!!!! //Can't believe, it works!!!!
Please, in this code:

std::cout << (void*)&myCharVar;


How to describe the procedure: what did I do?

Many thanks!!!
enemy wrote:
How to describe the procedure: what did I do?


The process is simple, here it is in more verbose terms:


1
2
3
4
5
6
7
8
9
10
11
char myCharVar = 'a';

//a regular char pointer is treated like a string
char* myCharPointer = &myCharVar;

//so we have to "cast" it to a different type, void* is simply a pointer without a type
//putting a type in () before a variable/type/value "casts" or converts it into the type
//in ()
void* myCharVoidPointer = (void*)myCharPointer;

std::cout << myCharVoidPointer;
Topic archived. No new replies allowed.