Thread: Printing the whole array's values.

  1. #1
    Banned
    Join Date
    Apr 2015
    Posts
    596

    Printing the whole array's values.

    Hi, I'm so curious to know if there's a quick way to printf whole the array's value, I tried to use this syntax
    Code:
     printf("%d", arr1);
    supposing I have
    Code:
     int arr1[5]={1,2,3,4,5}
    but didn't work very well...any idea/suggest to printf whole the whole array's value without using loop for/while!!



    thanks!

  2. #2
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,787
    Not really. You need a loop.

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    any idea/suggest to printf whole the whole array's value without using loop for/while!!
    Nope. If you want to print the array you need a loop of some kind.

    Jim

  4. #4
    Banned
    Join Date
    Apr 2015
    Posts
    596
    Alright...and in the same content of the arrays..


    How can I exactly pass an array between two functions? sorry if that's not relevant to ask like these questions but I really struggling alone to know how!!, can anyone elaborate and give any example of how to pass an array between two functions? thanks very very much!

  5. #5
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    What have you tried?

    Jim

  6. #6
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,787
    Actually, here is a solution that doesn't use a loop

    Code:
    #include <stdio.h>
    
    int parray(const int *a, size_t sz)
    {
        if (sz != 0) {
            int i = parray(a, sz - 1);
            printf("%d\n", i);
        }
        return a[sz];
    }
    
    int main(void)
    {
        int arr1[]={1,2,3,4,5};
        
        parray(arr1, sizeof arr1 / sizeof arr1[0]);
        
        return 0;
    }
    The only problem is that for all intents and purposes it's a loop

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 07-21-2013, 10:35 PM
  2. Printing out odd and even values of an array
    By phillyflyers in forum C Programming
    Replies: 9
    Last Post: 04-17-2013, 10:55 AM
  3. Trouble printing x and y values of struct points in an array?
    By arcadedragon in forum C Programming
    Replies: 6
    Last Post: 10-03-2012, 10:15 AM
  4. Replies: 3
    Last Post: 10-21-2010, 12:39 PM
  5. stuck printing values from array
    By Guti14 in forum C++ Programming
    Replies: 3
    Last Post: 09-10-2003, 09:56 PM