Pointers in C

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
User avatar
Diablo vt
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 26
Joined: Wed Oct 29, 2008 6:09 pm
Location: London

Pointers in C

Post by Diablo vt »

Alright guys I really need help on this. I'm finding it really hard to grasp the concepts of pointers. Could anyone direct me to a website regarding the subject or an explaination? Thanks all. I like C and it's going very well until the pointer lol. :)
There are 10 types of people in this world; those who understand binary and those who don't.
User avatar
programmerinprogress
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 632
Joined: Wed Oct 29, 2008 7:31 am
Current Project: some crazy stuff, i'll tell soon :-)
Favorite Gaming Platforms: PC
Programming Language of Choice: C++!
Location: The UK
Contact:

Re: Pointers in C

Post by programmerinprogress »

I think everyone gets confused by pointers to start with (I have to admit that although I understand what they do, and what you can do with them, I still have my anxieties about implementing them into my code)

Pointers are variables, variables that store a memory address.

A memory address is a location in the computer's memory.

All other variables are stored in the memory, and have an address.

You use a pointer to access the data at the stored memory address.

This is useful because you can manipulate the memory directly, which can be really useful, two reasons why you might use pointers are:
- you want to pass some values in a function, but passing them the normal way (by value) only makes copies of them, so by using pointers, you can manipulate the actual variable stored at the address in the pointer, instead of making copies.
- you're writing a program, but you don't know how much memory you need at the time of compiling (an example might be a map editor program, which is capable of creating maps of different sizes), with pointers you're able to use dynamic memory, i.e. you can access memory that can be allocated during the runtime of the program instead of when the code is compiled.

I don't actually know C, i'm a C++ man *grabs closest shield like object to defendself from C programmers throwing comments about atoi and atof at me :lol: *
(I joke of course), all I know is that you use malloc and free, and when you call malloc you have to use the sizeof keyword to determine the size of the memory you're pointing to (correct me if i'm wrong)

I hope this helped.
---------------------------------------------------------------------------------------
I think I can program pretty well, it's my compiler that needs convincing!
---------------------------------------------------------------------------------------
And now a joke to lighten to mood :D

I wander what programming language anakin skywalker used to program C3-PO's AI back on tatooine? my guess is Jawa :P
Post Reply