Thread: Function arguments

  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
    39,661
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 10-23-2012, 02: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-15-2011, 11:36 PM
  4. Arguments in function
    By mike_g in forum C Programming
    Replies: 3
    Last Post: 06-21-2007, 10:04 AM
  5. Replies: 9
    Last Post: 01-02-2007, 04:22 PM

Tags for this Thread