![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Not a user?
Join Date: Sep 2007
Posts: 308
Rep Power: 2
![]() |
Char memory address?
Declared variables:
c++ Syntax (Toggle Plain Text)
printed to command line: c++ Syntax (Toggle Plain Text)
and I get the following (garbage?) commandline Syntax (Toggle Plain Text)
this doesn't look like valid address notation to me, has anybody seen this before? This is on Vista 64 and it doesn't show as the squares in the command line, but looks like the screen shot below. Can anybody tell me why the address for e and f include the previous addresses and all the junk? |
|
|
|
|
|
#2 |
|
Not a user?
Join Date: Sep 2007
Posts: 308
Rep Power: 2
![]() |
Re: Char memory address?
If I had to guess, I'd say it's because it still allocates a byte for the chars, that's where the junk comes from, but wouldn't it still have a normal memory address? This is confusing.
|
|
|
|
|
|
#3 |
|
Battle Programmer
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 770
Rep Power: 3
![]() |
Re: Char memory address?
If I had to guess, I'd say the way to handle the addresses is ambiguous. You're basically giving cout a char* to print out, and you want the int value, but it's probably looking at it as a null-terminated string. Try casting the addresses to int and see what you get
__________________
<insert disclaimer here> <insert shameless plug for Visual Studio here> |
|
|
|
|
|
#4 | |
|
SEXY SHOELESS GOD OF WAR!
![]() Join Date: Jun 2005
Location: Wet west coast of Canada
Posts: 1,198
Rep Power: 5
![]() |
Re: Char memory address?
Quote:
int part (sizeof(int) and sizeof(char *) are not necessarily equal). When you pass it the address of a char, it receives a char *, and has no way of knowing you want to print the address, rather than a string. Remember that a C-style string, used in C++ as well, is just a series of zero or more char elements, followed by a char with the value zero to act as a terminator. Try something like this instead: C++ Syntax (Toggle Plain Text)
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot. - Vaarsuvius, Order of the Stick |
|
|
|
|
|
|
#5 |
|
Not a user?
Join Date: Sep 2007
Posts: 308
Rep Power: 2
![]() |
Re: Char memory address?
Thanks guys, I will digest this a bit and see if it can make sense to my old head.
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Hexadecimal Memory Address Question | 357mag | C++ | 1 | Jul 8th, 2007 10:19 PM |
| problem processing file into a char array | csrocker101 | C++ | 1 | May 9th, 2007 12:50 AM |
| address memory in an array | b1g4L | C++ | 9 | Feb 5th, 2006 3:33 AM |
| Copying memory address values | rsnd | C++ | 4 | Jun 19th, 2005 8:41 AM |
| Pointers in C (Part I) | Stack Overflow | C | 4 | Apr 28th, 2005 8:03 PM |