[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 865
  • Last Modified:

How do functions evaluate arguments?

I just want to know if I am on the right path.  The function will evaluate an argument like an error check?  Say for instance, if you are suppose to have numeric - it will evaluate the input whether it is numeric or alpha?  I am very confused with this.  I am just a beginner in C++, taking a class thorugh work and they did not have such good explainations on this subject enough for me to understand it.
0
Roni
Asked:
Roni
  • 4
  • 2
2 Solutions
 
AxterCommented:
The argument is evaluated at compile time, and if it does not match the function arugment type, or can not be converted via operators, than you'll get a compile error.
0
 
RoniAuthor Commented:
Can you give me an example?  I am still not understanding - so you are saying it does work like an error handler?
0
 
jkrCommented:
Basically, Axter is correct - however, just about the syntax. The is no logical evaluation, so you still could break functionality by passing nonsense values like e.g.

int Add(int a, int b) {

    return a + b;
}

Add((int) "one", (int) "two");

or

char arr[255] = "test";

strcat(test,(char*) 42);
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
AxterCommented:
>>so you are saying it does work like an error handler?

At compile time, yes.
But that's if you don't use explicit casting, as in jkr's example.

In general, you should avoid casting, because you're removing the compiler's ability to catch errors at compile time.
0
 
RoniAuthor Commented:
Thank you very much.  In reading your explainations and researching more, I now understand......thank you both again....
0
 
RoniAuthor Commented:
Okay....how do I change it?  
0
 
RoniAuthor Commented:
Thank you.....
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now