Thread: Storing ints into an array

  1. #1
    Registered User
    Join Date
    Sep 2018
    Posts
    15

    Storing ints into an array

    Code:
    #include<stdio.h>
    #include<stdlib.h>
    
    
    int main(void)
    {
    int i = 0, A[10];
    
    printf("Input a set of up to 10 integers separated by a space to store in Array A: ");
    fflush(stdout);
    
    for(i = 0; i<10; i++)
    {
        scanf("%d", &A[i]);
        printf( "%d", &A[i]);
        fflush(stdout);
    }
    
    return 0;
    }
    Input a set of up to 10 integers separated by a space to store in Array A: 1 2 3 4 5
    6422048 6422052 6422056 6422060

    Why is the array coming back as 6422048 for every input i put in. Im trying to create two arrays with up to ten variables, apparently struggling with just one.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    27,271
    You should print A[i], not &A[i].
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 11-03-2011, 05:06 PM
  2. fseek and storing ints
    By paperbox005 in forum C Programming
    Replies: 3
    Last Post: 04-04-2005, 09:39 AM
  3. Building an array of ints
    By Lone in forum C++ Programming
    Replies: 10
    Last Post: 01-31-2005, 01:07 PM
  4. array of ints
    By barim in forum C Programming
    Replies: 4
    Last Post: 01-01-2005, 05:21 AM
  5. Array of ints
    By Tiger in forum C Programming
    Replies: 8
    Last Post: 10-01-2001, 12:17 PM

Tags for this Thread