Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

C++ void function help

  1. Oct 7, 2005 #1
    I have to answer a homework problem due today that I am not sure how to do the problem reads.
    "Write a program that calls a void type function to find the maximum of three given integer numbers"
    We use visual studio.net, any help would be appreciated and I would like to be able to compile it and run the program so I can figure out how it works.
  2. jcsd
  3. Oct 7, 2005 #2
    never mind

    I got it thanks anyway
    // 7.3.cpp : Defines the entry point for the console application.
    #include <iostream>
    using namespace std;
    void max(int x, int y, int z)
    int max;
    cout<<"max= " << max<<endl;
    int main ()
    void max (int x, int y, int z);
    max(54, 27 ,35);

    return 0;
  4. Oct 7, 2005 #3


    User Avatar
    Science Advisor
    Homework Helper

    I got a problem with that: Your problem said "find" the maximum value. Well, just printing it to the screen is not "finding it" as far as I'm concerned. You know, now if you "stored" it to some variable name, then to me that would be considered "finding it". Suppose that might be a good thread in some "philosophy of computation" forum. Just what does "finding" it really mean?
    Last edited: Oct 7, 2005
  5. Oct 7, 2005 #4
    A void function is really just a subroutine. Specifying void as the return type means you dont include the final "return 0;" or whatever return value.

    When you call a function, keep in mind passing by value or passing by reference can sometimes affect your original value.

    If youre calling a value type, like Int, Char, Long etc, pass by val means your value sits on the stack and gets copied for use, so the copy doesnt affect the original. But never assume a pass by val leaves the original untouched
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?

Similar Discussions: C++ void function help
  1. Return type void (Replies: 1)