the address of an address does exist!!!
Code:
#include <stdio.h> the funny thing is the address of address does exist. Does it just happen by chance? |
Yes, address of address exists. If you store something in memory, like defined in main() variable "s" (which self is an address, but this is irrelevant), its address is available. As always remember that this variable will be destroyed at end of function, so make sure you will not access it beyond scope.
|
Quote:
Code:
#include <stdio.h> The address of string s is 0x400628 The address of address of string s is 0xf43c5a90 and stores 0x400628 e The address of address of string s is 0xf43c5a90 and stores 0x400629 l The address of address of string s is 0xf43c5a90 and stores 0x40062a l The address of address of string s is 0xf43c5a90 and stores 0x40062b o The address of address of string s is 0xf43c5a90 and stores 0x40062c The address of address of string s is 0xf43c5a90 and stores 0x40062d w The address of address of string s is 0xf43c5a90 and stores 0x40062e o The address of address of string s is 0xf43c5a90 and stores 0x40062f r The address of address of string s is 0xf43c5a90 and stores 0x400630 l The address of address of string s is 0xf43c5a90 and stores 0x400631 d The address of address of string s is 0xf43c5a90 and stores 0x400632 The address of address of string s is 0xf43c5a90 and stores 0x400633 The address of address of string s is 0xf43c5a90 and stores 0x400634 The address of address of string s is 0xf43c5a90 and stores 0x400635 The address of address of string s is 0xf43c5a90 and stores 0x400636 The address of address of string s is 0xf43c5a90 and stores 0x400637 T The address of address of string s is 0xf43c5a90 and stores 0x400638 h The address of address of string s is 0xf43c5a90 and stores 0x400639 e The address of address of string s is 0xf43c5a90 and stores 0x40063a The address of address of string s is 0xf43c5a90 and stores 0x40063b a The address of address of string s is 0xf43c5a90 and stores 0x40063c d look ,the address of the string's address doesnt change anyway. What's going on? |
Hi there,
Quote:
Code:
char *s = "hello world"; You could even change the characters that p points to. For example: Code:
char *s = "hello world"; Code:
#include <stdio.h>
Code:
The address of address of string s is 0xf43c5a90 and stores 0x400630 Then, finally, you recognize the beginning of the next string in your program, "The address of ...". That's how your variables are stored in memory. Quote:
The number of a hotel room doesn't change when guests check out and in. Like more analogies? - You really should get a grip on basics. [X] Doc CPU |
Thanks very much, DOC, I've been attaching my eyez on the where the pointer pionts to and if there is a pionter piont to it.
I just forget p is a variable, so OF CAUSE IT DOES HAS A ADDRESS. Quote:
|
Your problem is that the example you chose is more complex than you think.
Pointer variable s, and integer i are both on the stack. The string pointed to by s is on the heap. All are derived from additional pointers (s and i from the stack frame, which is pointed to by the stack pointer). The heap has its own pointer (usually a fixed base - fixed as in it is fixed for a specific program, it varies depending on the size of the program). Walking through a string (incrementing a pointer) is fine --- but the technique allows you to point to nonsense after you reach the end of the defined string... |
printf() has %p to give you the value in a pointer, hence you could've created a pointer to the string and used printf() to get you the result.
Code:
char *s = "hello world"; |
All times are GMT -5. The time now is 09:44 AM. |