Thread: Array manipulation doesn't work in printf

  1. #1
    Registered User
    Join Date
    Sep 2012
    Posts
    9

    Array manipulation doesn't work in printf

    I have this void function that modifies an array count[]. When I call this function inside printf, and print the resulting count[0] in the same printf, why isn't the array modified?
    Code:
    #include<stdio.h>
    
    
    int test(int n, int count[])
    {
        count[0]++;
        return 8;
    }
    
    
    int main()
    {
        int count[5] = {0};
        printf("%d %d", test(5,count), count[0]);
        return 0;
    }
    The output is 8 0 instead of 8 1.

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    printf, like any function, is free to evaluate its' arguments in any order.

  3. #3
    Registered User
    Join Date
    Sep 2012
    Posts
    9
    I see. Thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 12-07-2010, 06:53 AM
  2. Why doesn't it work???
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 09-23-2006, 08:24 PM
  3. dynamic union array doesn't work
    By Mathsniper in forum C Programming
    Replies: 2
    Last Post: 05-08-2005, 08:46 AM
  4. assigning 2d array to type **arr doesn't work
    By scoobasean in forum C++ Programming
    Replies: 7
    Last Post: 02-26-2005, 03:14 PM
  5. my function doesn't work! it should work
    By Unregistered in forum C Programming
    Replies: 13
    Last Post: 05-02-2002, 02:53 PM