Thread: Question about passing arguments to functions (using array)

  1. #1
    Registered User
    Join Date
    Oct 2016
    Posts
    2

    Question Question about passing arguments to functions (using array)

    Hi everyone,

    I have a few questions, because I am new to C.
    I tried to use arguments in functions.
    It worked with normal numbers.
    But when I tried to use an array (with float) it didn't work.
    On the internet I tried to search for more information about this, but I couldn't find anything. Can someone please tell me what I have done wrong?
    Thank you in advance!

    Code:
    #include <stdio.h>
    #include <string.h>
    
    void printValues(float values, int size);
    
    int main()
    {
        
        int int_Array[10] = {1.5, 2.2, 7.3, 9.2, 7.4, 7.5, -8.0, 1.5, 12};
        float float_Array[10] = {1.5, 2.2, 7.3, 9.2, 7.4, 7.5, -8.0, 1.5, 12};
        
        for (int i = 0; i < 9; ++i) {
            float_Array[9] = (float)int_array[9];
        }
            
        printValues(float_Array[9]);
        return 0;
    }
    
    void printValues(float values, int size)
    {
        printf("Values: %d\n", float_Array[9]);
        return;
    }

  2. #2
    Registered User
    Join Date
    Feb 2012
    Posts
    347
    For integer array you are initialising with float values that is not what you want I think. While printing float values you should use %f format specifier.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question : Passing Array Arguments as Pointers
    By NEMEAN in forum C Programming
    Replies: 1
    Last Post: 12-04-2010, 03:33 PM
  2. Replies: 7
    Last Post: 11-21-2008, 04:27 PM
  3. Passing arguments between functions
    By Wiretron in forum C Programming
    Replies: 4
    Last Post: 05-17-2006, 04:59 PM
  4. Passing functions as arguments
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 02-13-2002, 11:02 PM
  5. passing arguments through functions
    By cwd in forum C Programming
    Replies: 2
    Last Post: 09-30-2001, 06:07 PM

Tags for this Thread