For a given function in c the argument type which

This preview shows page 18 - 21 out of 21 pages.

For a given function in C, the argument type which corresponds to the domain in mathematics – is the data type that C expects for an argument of that function. For example: the argument type of abs is int ; the argument type of fabs is float . 18
Image of page 18
Argument Type Mismatch ©LPU CSE101 C Programming An argument type mismatch is when you pass an argument of a particular data type to a function that expects a different data type. Some implementations of C WON’T check for you whether the data type of the argument you pass is correct. If you pass the wrong data type, you can get a bogus answer. This problem is more likely to come up when you pass a float where the function expects an int . In the reverse case, typically C simply promotes the int to a float . 19
Image of page 19
#include <stdio.h> #include <math.h> int main () { const float pi = 3.1415926; printf("2.0 = %f\n", 2.0); printf("pi = %f\n", pi); printf("cos(pi) =%f\n", cos(pi)); printf("sin(pi) = %f\n", sin(pi)); printf("sqrt(2.0) = %f\n", sqrt(2.0)); printf("sqrt(2.0)/2= %f\n", sqrt(2.0)/ 2 ); } Implementation of in-build function 2.0 = 2.000000 pi = 3.141593 cos(pi) = -1.000000 sin(pi) = 0.000000 sqrt(2.0) = 1.414214 sqrt(2.0) / 2 = 0.707107
Image of page 20
[email protected] Next Class: Call by Reference and Call by value ©LPU CSE101 C Programming 21
Image of page 21

You've reached the end of your free preview.

Want to read all 21 pages?

  • Fall '19
  • Continuous function

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture