pointers help!

adress allocation

Page 1 of 1

5 Replies - 606 Views - Last Post: 11 October 2008 - 07:51 AM Rate Topic: -----

#1 cpro  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 25-September 08

pointers help!

Post icon  Posted 10 October 2008 - 07:55 AM

pls clarify this, :blink:

pointers r the one which hold memory adresses right so,

to hold those pointers some other variable is required to store tat number(the adress number)

i mean suppose if i declre a variabe = some 30 so wat happens is this 30

goes to a memory allocation say 2000, again to store tat 2000 is

someother variable wil be automatically assigned by the computer so as to

store the memory adress 2000 anmd den to store this 2000 number is

someother pointer variable is automatically assigned by the computer

like tat...........infinity , if it is wrong

then how does the computer assign a number adress as 2000 or 5000 or

watever to store the number 30 i mean does it select randomly also

pls xplain the main importance y pointers are used in programs :blink:

i couldnt understand

Is This A Good Question/Topic? 0
  • +

Replies To: pointers help!

#2 UG Cyber  Icon User is offline

  • D.I.C Addict

Reputation: 32
  • View blog
  • Posts: 556
  • Joined: 24-July 08

Re: pointers help!

Posted 10 October 2008 - 08:29 AM

its magic....
Was This Post Helpful? 0
  • +
  • -

#3 csmanoj  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 10
  • View blog
  • Posts: 150
  • Joined: 06-August 07

Re: pointers help!

Posted 10 October 2008 - 11:41 AM

Your compiler creates this thing called a symbol table. It stores information about the variables that you've specified and variables that the compiler may have created for internal purposes. Information like the type of data, the address, and the variable name. So when you create a pointer called ptr, what happens is it creates memory for a pointer type, usually 2 bytes. Puts something like 'ptr-pointer-0x2045' in the symbol table. This means that at 0x2045, theres a memory location address, and the programmer thinks it's called ptr.

If you want to resolve a variable's address, the computer only looks up in the symbol table. So if you have 'a-int-0xf12a' in the symbol table and write int *adr = &a in your program, the computer fetches 0xf12a from the symbol table coz that's what is the address in the symbol table. It is the address of the variable a. It stores this address in arbitrary memory location, say 0x2faa. Then creates a new entry in the symbol table that holds 'adr-pointer-0x2faa'. But if you write int x = a, it looks up again at the symbol table, but this time, it goes to the address 0xf12a in the memory, and retrieves the the data stored in that memory. It stores this value in a new location, say 0x1122, and creates a new symbol table entry that says 'x-int-0x1122'. Note that working with pointers is in reality more straightforward for computers than working otherwise. That's why pointers are so powerful.

For more indepth info, refer to a good book on computer architecture. It'll explain to you better.

This post has been edited by csmanoj: 10 October 2008 - 12:00 PM

Was This Post Helpful? 0
  • +
  • -

#4 cpro  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 25-September 08

Re: pointers help!

Posted 10 October 2008 - 07:54 PM

thanks a lot guys for your help
Was This Post Helpful? 0
  • +
  • -

#5 Bench  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 857
  • View blog
  • Posts: 2,343
  • Joined: 20-August 07

Re: pointers help!

Posted 11 October 2008 - 01:13 AM

Have a look at the pointers-related links posted in this thread
http://www.dreaminco...mp;#entry431701
Was This Post Helpful? 0
  • +
  • -

#6 cpro  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 25-September 08

Re: pointers help!

Posted 11 October 2008 - 07:51 AM

thx bench
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1