
- Forum
- Programming Talk
- C and C++
- 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?
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?...
-
09-26-2008, 01:29 PM #1
- 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?

-
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.
-
Can you say me what happens if there is no prototype defined for the same example as explained by you.
-
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

Reply With Quote





