Thread: Input on arrays and pointers

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    115

    Input on arrays and pointers

    Hi everyone I am trying hard reading books and using the internet to better understand pointers, structures and arrays. I posted what I think I know thus far below and would like anyone to correct my mistakes or assumptions thus far. Thanks in advance.

    WHEN USING CHAR POINTERS

    P = ENTIRE STRING

    &P = ADDRESS OF THE POINTER

    *P = 1RST BLOCK OF THE STRING (IN EG BELOW POINTS TO 'T')

    *(P + 2) = 3RD BLOCK OF THE STRING (IN EG BELOW POINTS TO 'i')

    THE POINTER MUST BE INITIALIZED AND VALUES ASSIGNED
    IN A MANNER SUCH AS BELOW:

    char *carl;
    carl = "This is helping me learn";

    ------------------------------------------------------------------------------------------

    WHEN USING INT POINTERS

    P = ADDRESS OF THE CONTENTS P IS POINTING TO (IN EG BELOW ADDRESS OF 500)

    &P = ADDRESS OF THE POINTER ITSELF (INT *P's ADDRESS)

    *P = CONTENTS OF THE POINTER (1 BLOCK OF MEMORY)

    THE POINTER MUST BE INITIALIZED AND VALUES ASSIGNED
    IN A MANNER SUCH AS BELOW:

    int time = 500;

    int *carl2;

    carl2 = &time;

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    carl = "This is helping me learn";
    carl should be declared as const char*

    IN EG BELOW POINTS TO 'i'
    P + 2 - points to 'i'
    *(P+2) evaluates to 'i'
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  3. #3
    Registered User
    Join Date
    Apr 2008
    Posts
    115

    Thanks

    Thank you for the feedback. I am starting pointers to structures next so back to the book.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pointers and multi dimensional arrays
    By andrea72 in forum C++ Programming
    Replies: 5
    Last Post: 01-23-2007, 04:49 PM
  2. Passing pointers to arrays of char arrays
    By bobthebullet990 in forum C Programming
    Replies: 5
    Last Post: 03-31-2006, 05:31 AM
  3. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM
  4. Arrays of pointers (input)
    By tyskater in forum C Programming
    Replies: 10
    Last Post: 12-17-2003, 12:00 AM
  5. Help understanding arrays and pointers
    By James00 in forum C Programming
    Replies: 2
    Last Post: 05-27-2003, 01:41 AM