Function arguments

This is a discussion on Function arguments within the C Programming forums, part of the General Programming Boards category; Can someone explain to me why this bit of code works and the commented version of double functest doesnt. dont ...

  1. #1
    Registered User
    Join Date
    Dec 2012
    Posts
    1

    Function arguments

    Can someone explain to me why this bit of code works and the commented version of double functest doesnt. dont understand functions very well it seems...
    insert
    Code:
    /*****START**/
    
    #include<stdio.h>
    #include<stdlib.h>
    typedef struct
    {
        //
        double test1;
        double test2;
    }t;
    t tab;
    t * q = &tab;
    double functest(void);
    int main()
    {
        //
        printf("enter test1\t");
        scanf("%lg",&q->test1);
        printf("\nenter test2\t");
        scanf("%lg",&q->test2);
    /*    printf("hence function returns %lg",functest(q->test1,q->test2));*/
        printf("hence function returns %lg\n",functest());
        return 0;
    }
    
    
    /*double functest(double q->test1,double q->test2)*/
    /*{*/
    /*    return q->test1 * q->test2;*/
    /*}*/
    
    
    double functest(void)
    {
        double res;
        res=q->test1*q->test2;
        printf("answer is%lg",res);
        return res;
    
    
    }
    /****END***/
    How do you provide arguments to a function where the variable is in a struct???

    Thanks for your help

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,852
    Well you need to declare it as something like
    double functest(double a, double b);
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 10-23-2012, 03:37 PM
  2. function with variable function arguments
    By Kyl in forum C Programming
    Replies: 10
    Last Post: 12-21-2011, 02:56 PM
  3. Function does not take 0 arguments
    By caprice150 in forum C++ Programming
    Replies: 7
    Last Post: 10-16-2011, 12:36 AM
  4. Arguments in function
    By mike_g in forum C Programming
    Replies: 3
    Last Post: 06-21-2007, 11:04 AM
  5. Replies: 9
    Last Post: 01-02-2007, 04:22 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21