Are words argument and parameter interchangeable cs

  • Thread starter PainterGuy
  • Start date
  • #1
689
33

Main Question or Discussion Point

hello everyone, :wink:

one short question. it is said function sqrt() takes argument inside the parenthesis. sometimes word parameter is also used. are they interchangeable? i am speaking in terms of c++.

is int main() has any similarity to math functions such as f(x)=2x+7. but the problem is int main() does take any value inside the "()". i am a beginner. so short explanation is enough. many many thanks for this help and leading me on the right path.

cheers
 

Answers and Replies

  • #2
297
2
hello everyone, :wink:

one short question. it is said function sqrt() takes argument inside the parenthesis. sometimes word parameter is also used. are they interchangeable? i am speaking in terms of c++.
In that context, yes, they are generally used interchangeably. However, technically, C++ defines a clear difference between them. From the standard:

C++ Standard said:
argument: An expression in the comma-separated list bounded by the parentheses in a function call expression, a sequence of preprocessing tokens in the comma-separated list bounded by the parentheses in a function-like macro invocation, the operand of throw, or an expression, type-id or template-name in the comma-separated list bounded by the angle brackets in a template instantiation. Also known as an “actual argument” or “actual parameter.”

parameter: an object or reference declared as part of a function declaration or definition, or in the catch clause of an exception handler that acquires a value on entry to the function or handler; an identifier from the comma-separated list bounded by the parentheses immediately following the macro name in a function-like macro definition; or a template-parameter. Parameters are also known as “formal arguments” or “formal parameters.”
So here x and y are parameters:

int function(int x, int y);

And here they are arguments:

function(x, y);

Of course, most programmers aren't even aware of the distinction. And most of the rest largely ignore it.

is int main() has any similarity to math functions such as f(x)=2x+7. but the problem is int main() does take any value inside the "()". i am a beginner. so short explanation is enough. many many thanks for this help and leading me on the right path.
Well, it's certainly based on the idea of a mathematical function. Of course, a "function" that doesn't return a value is sometimes called a "procedure", but for the purposes of C++, we just call them all functions, regardless. To be precise, if it doesn't return a value, it's often called a void function in C/C++.

Let's just say it's based on the mathematical function, but isn't always strictly a mathematical function.

However, do note that int main() is only one way. It can have parameters (which are passed in from command line arguments). It can also be:

int main(int argc, char *argv[])

where argc is the number of arguments passed in on the command line, and argv is an array of C character strings that are the arguments themselves. It's just that you can leave them out if you don't need them.
 
  • #3
AlephZero
Science Advisor
Homework Helper
6,994
291
is int main() has any similarity to math functions such as f(x)=2x+7. but the problem is int main() does take any value inside the "()".
The important thing about the syntax of a programming language is that is should be easy to both humans and computers to understand. The () are there to distinguish between a simple variable, and a function with no arguments.

Actually that statement is not quite true, but if you are a beginner, you might not know about pointers yet, and the "full disclosure" explanation probably won't mean much. Just be aware that it is sometimes legal and meaningful to use a function name WITHOUT the (). What you are doing then is referring to the function as a "thing", rather than actually calling it to return a value. A rather artifical (and incomplete, so don't try to run it!) example would be something like

if (some condition) f = sqrt;
else f = exp;
y = f(x);

which does almost the same thing as

if (some condition) y = sqrt(x);
else y = exp(x);

If you can't see why anybody would want to write code like that, don't worry about it. Just take it on trust for now that there are times when it is useful.
 
  • #4
689
33
And most of the Well, it's certainly based on the idea of a mathematical function. Of course, a "function" that doesn't return a value is sometimes called a "procedure", but for the purposes of C++, we just call them all functions, regardless. To be precise, if it doesn't return a value, it's often called a void function in C/C++.

Let's just say it's based on the mathematical function, but isn't always strictly a mathematical function.

However, do note that int main() is only one way. It can have parameters (which are passed in from command line arguments). It can also be:

int main(int argc, char *argv[])

where argc is the number of arguments passed in on the command line, and argv is an array of C character strings that are the arguments themselves. It's just that you can leave them out if you don't need them.
many thanks Grep and AlephZero. you guys are so nice, learning a lot from you. if you think answer to below question would be over my head then you jus please tell me.

sqrt() is also a function and found in some library file which perhaps also contain other other math related stuff. at the top header file #include <cmath> tell tells compiler to go for this library file when perhaps linking the code to executable. is this somewhat correct? tell me plz.

what is so special about int main() function that all other functions (as far as know and i have coded only 4 simple programs till now :) ) are contained within its body "{ }". is it some type of 'master' function and other subordinates.

is void main() taken nonstandard in c++?

please teach me on this. much grateful for this kind help.

note:--- there is a mistake in my first post. i think you understoodthe mistake.
is int main() has any similarity to math functions such as f(x ) = 2x + 7. but the problem is int main () does NOT take any value inside the "()".
cheers
 
Last edited:
  • #5
jtbell
Mentor
15,549
3,488
what is so special about int main() function that all other functions (as far as know and i have coded only 4 simple programs till now :) ) are contained within its body "{ }".
Other functions are not contained within the body of main(), that is, not like this:

Code:
int main ()
{

    void foo(int a, int b)
    {

    }

    int bar (double c)
    {

    }

    foo (x, y);
    z = bar (w);

}
but instead always like this, in which the bodies of foo() and bar() are outside the body of main():

Code:
void foo(int a, int b)
{

}

int bar (double c)
{

}

int main ()
{
    foo (x, y);
    z = bar (w);
}
What makes main() special is that the compiler always assumes it to be the entry point for the whole program. That is, the first statement executed is the first executable statement of main(). [except for constructor functions, which you won't see until you start learning about "classes" and object-oriented programming]

is void main() taken nonstandard in c++?
Yes, void main() is non-standard, both in C++ and in C. Some badly-written books use it, and many compilers accept it, nevertheless. I don't know for sure why, but I think it was once a Microsoft-ism.

Here are some comments on void main () from Bjarne Stroustrup, the original creator of C++, and whose book "The C++ Programming Language" was considered to be the de-facto "standard" for C++ before the ISO standard was adopted:

http://www2.research.att.com/~bs/bs_faq2.html#void-main
 
Last edited:

Related Threads on Are words argument and parameter interchangeable cs

  • Last Post
Replies
4
Views
2K
  • Last Post
Replies
6
Views
650
Replies
5
Views
517
  • Last Post
Replies
6
Views
3K
  • Last Post
Replies
4
Views
13K
  • Last Post
Replies
0
Views
1K
  • Last Post
2
Replies
35
Views
4K
Replies
6
Views
2K
  • Last Post
Replies
6
Views
9K
Replies
3
Views
2K
Top