Thread: Input functions calling

  1. #1
    Registered User
    Join Date
    Oct 2017
    Posts
    13

    Input functions calling

    If a function is defined as

    Code:
    int myfunction (int var1, int var2, struct mystruct *structname, double x, int x_flag) {
    
    ...
    
    return 0;
    }
    And if I want to use all these variables I call it:

    Code:
    myfunction(var1, var2, &structname, x, x_flag)
    But in the case when I don't have/need some of the variables, I would like to write zeros.
    Code:
    myfunction (var1, var2, NULL, 0, 0)
    What I would like to know is if I can simply write integer 0 instead of the double or float value that I am not using, or it has to be 0.0, i.e. written in double/float format and not integer?
    Does it depend on the compiler?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    25,861
    Yes, you could write the integer literal 0 instead of the double literal 0.0 as the conversion of 0 from integer to double will happen safely. Of course, you might still choose to use a double literal so as to make it clear to the reader that that argument corresponds to a double parameter.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Calling C .lib functions from C#
    By eddyq in forum C# Programming
    Replies: 3
    Last Post: 10-15-2015, 08:48 AM
  2. calling functions
    By njasmine1 in forum C Programming
    Replies: 2
    Last Post: 12-29-2010, 10:28 AM
  3. Replies: 12
    Last Post: 04-12-2009, 05:49 PM
  4. Calling functions
    By Kreathyr in forum C++ Programming
    Replies: 16
    Last Post: 02-23-2009, 01:09 PM
  5. I need some help on calling other functions in C
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 04-23-2002, 12:07 PM

Tags for this Thread