Printing Address of pointer

Hello. I am trying to print the address of some pointers, but I am confused.
When I run the program, it printed the whole thing of the user_entry instead of the address of the first indexed value of user_entry, and the last indexed value of the user_entry instead of the address of the last indexed value. How to change it? Thank you in advance.

Below is part of my program.

int main()
{
bool is_a_Palindrome, go_again;
int maxSize = 80;
char user_entry[80];

do
{
inputString(user_entry, maxSize);
is_a_Palindrome = isPalindrome(user_entry);
displayResult(is_a_Palindrome);
printAddresses (user_entry, is_a_Palindrome, maxSize);
go_again = goAgain();

} while (go_again == true);

return 0;
}


void printAddresses(char* user_entry, bool &is_a_Palindrome, int &maxSize)
{
char* front = user_entry;
char* back = (user_entry + strlen(user_entry) - 1);
bool* boolPtr = &is_a_Palindrome;
int* sizePtr = &maxSize;

cout << "The beginningaddress of the c-string is " << front
<< ",\nand theaddress of the last character is " << back << endl;
cout << "The address of the bool is " << boolPtr << endl;
cout << "The address of the cstring size int is " << sizePtr << endl;
}

Sample Dialogue:
Enter a string to test for palindrome:
sdfsdf
The entry is not a palindrome
The beginning address of the c-string is sdfsdf,
and the address of the last character is f
The address of the bool is 0018FD6B
The address of the cstring size int is 0018FD50
Would you like to go again? Y/y for yes, any other char for no.
Last edited on
Please use code tags when posting

For char array you need to cast to a void*

1
2
3
4
5
6
7
8
9
#include <iostream>

int main()
{
    char arr[] = "Hello World!";

    std::cout << "Print the c string " << arr << std::endl;
    std::cout << "Print the address " << static_cast<void*>(arr) << std::endl;
}
Last edited on
I also think it is possible deference the char array, to get the address.

Topic archived. No new replies allowed.