Thread: Scary: Array and pointers......

  1. #1
    Registered User
    Join Date
    Oct 2012

    Lightbulb Scary: Array and pointers......

    I'm really scared about array and pointers.. Whenever I'm going to those topics, I'm not getting anything.. Unable to understand... I understand everything thru pictorial representation, is this method a problem? I want to understand Array & Pointer and have to use that in a tool. Any suggestions/advice ??

  2. #2
    Registered User
    Join Date
    Jun 2005
    I've no idea by what you mean by " I want to understand Array & Pointer and have to use that in a tool".

    A pictorial representation of pointers or arrays is not specifically a problem for understanding, if that's the way your mind works. The main trap I see with pictorial representations is that people over-simplify, leave out key details that are critical to understanding - but people with other mindsets do that too. The bigger problem will be that you need to take a deep breath, relax, and spend more time working to understand what pointers are, what arrays are, and how to use them. The more you try to take learning shortcuts, the more likely you are to get into trouble with pointers or with arrays (or both).

    Without knowing what you're having trouble with, it is hard to give you more specific advice (particularly as nobody can write a complete introduction to pointers and arrays at the drop of a hat).
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  3. #3
    Registered User
    Join Date
    Sep 2006
    I think of arrays like a wall of mailboxes. Char arrays are the smaller mailboxes, and arrays of structs are the big mailboxes. The name of the array refers to the first array "mailbox", so it's VERY close to being a constant pointer (which is just a mailbox itself that holds an address, instead of a char, an int, or other data type). Since the name of the array is so close to being a constant pointer, you can't change the address of the array, and when you call a function with an array name as a parameter two things happen:

    1) the array name "decays" to being just a constant pointer (almost),


    2) you can't use sizeof(arrayName) and get the size of the array, anymore. You'll get the size of the pointer, instead.

    Arrays indices start at 0 and stop at N-1, where N is the number of elements of the array: array[5] indices go from array[0] to array[4]. By far the most common problem with arrays is having the index run to array[N] or beyond. But array[N-1] is the last valid index.

    With pointers, remember that they are like an unmagnetized compass needle when they're first created - they point ANYWHERE if they are created inside a function. That makes sense because local variables that are created are also set to garbage values. Only variables (and pointers), created outside any local function (having "Global scope", are assigned an initial value of 0, or '\0', or NULL for a pointer.

    Click on the "C Tutorial" tab at the top of this forum, and run through that. If you have any specific questions about some code, post them. Above all, you have to practice using arrays and pointers, to fully understand them. There are standard idioms for using them, and I strongly suggest you use them in your programs. Like swimming, you do have to get into the water and practice your skills, or you won't really learn how to do it well.

  4. #4
    Registered User
    Join Date
    Oct 2012
    @grumpy: I will spend more time working on it..

    @adak: Mailboxes story is very nice.. I will try practiing more and ask doubts.

    Thank you..
    Last edited by wall-e; 11-06-2012 at 03:29 AM. Reason: small correction

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Scary stuff...
    By JoshR in forum A Brief History of
    Replies: 10
    Last Post: 07-22-2005, 05:53 AM
  2. Scary! AHHH!!
    By face_master in forum A Brief History of
    Replies: 2
    Last Post: 12-18-2002, 09:33 AM
  3. hmm, scary but fun
    By moi in forum A Brief History of
    Replies: 4
    Last Post: 10-30-2002, 11:48 AM
  4. scary online ads: how successful are they?
    By toaster in forum A Brief History of
    Replies: 9
    Last Post: 08-22-2002, 10:55 AM
  5. IE 6 is actually scary...
    By Yoshi in forum A Brief History of
    Replies: 27
    Last Post: 02-04-2002, 12:14 AM