Thread: How do i assign pointers to specific array values?

  1. #1
    Registered User
    Join Date
    Sep 2017
    Posts
    12

    How do i assign pointers to specific array values?

    Am i assigning the pointers incorrectly?
    for (c = 0; c < 5; c++)

    printf("%d\n", array[c]);
    *p1 == array[0];
    *p2 == array[1];
    *p3 == array[2];
    *p4 == array[3];
    *p5 == array[4];
    printf("\n");
    printf("%d\n", *p1);
    printf("%d\n", *p2);
    printf("%d\n", *p3);
    printf("%d\n", *p4);
    printf("%d\n", *p5);
    return 0;

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    = is assignment, == is comparison.

    Also this is probably wrong conceptually... you can do *px = array[c] if px is already storing an address.

    What would probably work best is

    px = &array[c];
    where x is some pointer number like p1, and c is some array subscript.

  3. #3
    Registered User
    Join Date
    Sep 2017
    Posts
    12
    I should have caught that. Thank you very much.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How do I assign values to elements of a 2D array?
    By Karyumi in forum C Programming
    Replies: 9
    Last Post: 06-21-2012, 02:48 PM
  2. Assign values to array of structures
    By rlesko in forum C++ Programming
    Replies: 8
    Last Post: 12-12-2010, 03:31 PM
  3. Assign values to a set of array of structures
    By glucosonte in forum C Programming
    Replies: 1
    Last Post: 08-26-2009, 08:10 AM
  4. Assign an arrays values to another array
    By laczfinador in forum C Programming
    Replies: 3
    Last Post: 05-06-2009, 07:46 AM
  5. 3-d array assign string values
    By WaterNut in forum C++ Programming
    Replies: 8
    Last Post: 07-01-2004, 12:02 AM

Tags for this Thread