Solved

Calling a function

Posted on 2003-11-23
7
544 Views
Last Modified: 2010-04-15
When I want to call a function. Do you have to send a parameter to it or can you just leave it blank.  It is void function so there will be nothing returned.  
0
Comment
Question by:buckeyes33
  • 3
  • 2
  • 2
7 Comments
 
LVL 24

Expert Comment

by:shivsa
ID: 9806847
it depends on the declration of functions.

if the function is declared to have 2 parameter as input, it should be supplied 2 parameters.
void returning take care of what is expected to return back from function.
0
 
LVL 4

Expert Comment

by:n_fortynine
ID: 9806854
It depends on the so-called parameter list of your function.
For example:
void foo(void);  //equivalent to void foo( ).
Call: foo();       //legal
       foo(someParam); //illegal. foo does not take any parameter.

void foo1(int x); //or any number of parameters.
Call: foo1(); //illegal.
       int a = 0;
       foo1(a); //legal.
       char ch = 'a';
       foo1(ch); //warning. usually type casting is required for parameters whose types don't match that specified in the
                     //parameter list.
       foo1(a, ch); //error. foo1 does not take 2 parameters.

So my advise is, look up the prototype of your function. What types of parameters does it take? And how many?

0
 
LVL 24

Expert Comment

by:shivsa
ID: 9806857
void swap(double& x, double& y)
{                                                         /* exchange the values of x and y */
double temp = x;
x = y;
y = temp;
}


int main(){
 double a = 22.2, b = 44.4;
swap(a,b);
}

here function is void swap( para1, para2)

then here it need 2 input parameters and it will return nothing.
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 9

Author Comment

by:buckeyes33
ID: 9806868
I did not make much sense before.  
I calling function X.  function X is going to do all calculations needed and then print results.  This is without using the parameter that is would be sent to function X.

Is there a need to send a parameter to function X since it would not be needed.  
0
 
LVL 4

Accepted Solution

by:
n_fortynine earned 125 total points
ID: 9806945
If your function does not NEED the parameter, but its prototype DEMANDS on, you'll still need to suplly one to it. Even a dummy one.

Another way is to make the function taking in default parameters:
For example:
void foo(int x);
Call: foo(); //error.
       int a = 0;
       foo(a); //OK.

void foo1(int x = 0);
Call: foo1(); //OK now that you don't supply one, if foo1 needs to use x, x will have a value set at 0.
       int a = 2;
       foo1(a); //OK. Now foo1 will use x = 2.
0
 
LVL 4

Expert Comment

by:n_fortynine
ID: 9806949
>>DEMANDS on
should read... DEMANDS one.
0
 
LVL 9

Author Comment

by:buckeyes33
ID: 9806978
ok thanks.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now