Exforsys
+ Reply to Thread
Results 1 to 4 of 4

What happends if we try to pass he wrong types of arguments to a function?

This is a discussion on What happends if we try to pass he wrong types of arguments to a function? within the C and C++ forums, part of the Programming Talk category; What happends if we try to pass he wrong types of arguments to a function?...

  1. #1
    thanlong01 is offline Junior Member Array
    Join Date
    Sep 2008
    Answers
    1

    What happends if we try to pass he wrong types of arguments to a function?

    What happends if we try to pass he wrong types of arguments to a function?



  2. #2
    Allan is offline Member Array
    Join Date
    May 2006
    Answers
    40
    If you call a function with wrong type of arguments passed to it then here comes the role of function prototype defined. That is the actual argument gets converted to the type of the formal argument that is ‘as if by assignment’.

    For example

    main()
    {
    .......
    int i;
    double s(double); /* This denotes prototype function */
    ....
    s(i); /* Here function called with integer as argument*/
    .....
    }

    double s(double j){ /* This denotes function definition */
    {
    .....
    ...
    }

    In the above example function s prototype indicates that it takes a single argument of type double. But argument by which function is called in main is integer. So in this case int is argument int is converted to prototype argument double and then function is called.


  3. #3
    blenda is offline Member Array
    Join Date
    May 2006
    Answers
    36
    Can you say me what happens if there is no prototype defined for the same example as explained by you.


  4. #4
    Allan is offline Member Array
    Join Date
    May 2006
    Answers
    40
    If suppose you have not defined any protype for the same function s as in the example above and you have passed wring arguments same as in example then only int type would get passed to the function. Also one important thing to note here is the conversion rule varies depending on the argument type. For instance if the type of the argument is float it would get converted to double


    •    Sponsored Ads



Latest Article

Network Security Risk Assessment and Measurement

Read More...