Are words argument and parameter interchangeable cs

Click For Summary

Discussion Overview

The discussion revolves around the terminology used in C++ programming, specifically the interchangeability of the terms "argument" and "parameter," as well as the nature of the main function in C++. Participants explore the similarities between C++ functions and mathematical functions, and clarify the role of the main function in program execution.

Discussion Character

  • Technical explanation
  • Conceptual clarification
  • Debate/contested
  • Homework-related

Main Points Raised

  • Some participants suggest that "argument" and "parameter" are generally used interchangeably in programming, but technically, they have distinct definitions in C++. Arguments are expressions passed to functions, while parameters are variables defined in function declarations.
  • There is a discussion on the nature of the main function in C++, with some participants noting that it is based on the concept of mathematical functions but does not always behave like one, particularly when it comes to returning values.
  • Some participants explain that int main() can accept command line arguments, which can be represented as int main(int argc, char *argv[]), but it can also be defined without parameters.
  • One participant raises a question about the special status of the main function, suggesting it serves as the entry point for the program, while other functions are defined outside of it.
  • There is a clarification that void main() is considered non-standard in C++, with some participants referencing its acceptance by certain compilers despite being discouraged in standard practice.
  • Participants express gratitude for the explanations provided and seek further clarification on related topics, such as the inclusion of libraries and the structure of functions in C++.

Areas of Agreement / Disagreement

Participants generally agree on the technical definitions of arguments and parameters, but there is some uncertainty regarding the implications of these terms in practical programming. The discussion about the main function's role and the use of void main() reveals differing opinions on its standardization.

Contextual Notes

Some participants note that the distinction between arguments and parameters may not be widely recognized among programmers, and there are nuances in how functions are defined and called in C++ that may not be immediately clear to beginners.

Who May Find This Useful

Beginners in C++ programming, educators teaching programming concepts, and those interested in the technical distinctions between programming terminology.

PainterGuy
Messages
938
Reaction score
73
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
 
Technology news on Phys.org
PainterGuy said:
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.

PainterGuy said:
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.
 
PainterGuy said:
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.
 
Grep said:
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 please.

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:
PainterGuy said:
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:

Similar threads

  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 10 ·
Replies
10
Views
4K
  • · Replies 7 ·
Replies
7
Views
5K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 27 ·
Replies
27
Views
23K
  • · Replies 19 ·
Replies
19
Views
5K
  • · Replies 3 ·
Replies
3
Views
4K
Replies
13
Views
4K
  • · Replies 3 ·
Replies
3
Views
6K