Are words argument and parameter interchangeable cs

In summary, the function sqrt() and parameter are generally used interchangeably in C++, although there is a technical difference between them. The function int main() is based on the idea of a mathematical function, but can also have parameters in some cases. The syntax of a programming language should be easy for both humans and computers to understand. The function int main() is often called the "master" function and contains other subordinate functions within its body. Using void main() is nonstandard in C++. The header file #include <cmath> directs the compiler to use the library file that contains math related functions such as sqrt().
  • #1
PainterGuy
940
69
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
  • #2
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.
 
  • #3
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.
 
  • #4
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:
  • #5
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:

1. Are the words "argument" and "parameter" interchangeable in computer science?

While the words "argument" and "parameter" are often used interchangeably in everyday language, they have distinct meanings in computer science. An argument is a value that is passed into a function or method, while a parameter is a variable that is used to define a function or method. So while both terms refer to values used in a function, they serve different purposes and are not interchangeable.

2. Can I use the terms "argument" and "parameter" interchangeably in my code?

No, it is important to use the correct terminology in your code to avoid confusion and potential errors. Be sure to use "argument" when referring to values passed into a function and "parameter" when defining the function.

3. What is the difference between an argument and a parameter in computer science?

As mentioned before, an argument is a value passed into a function, while a parameter is a variable used to define a function. Another important difference is that arguments are provided by the caller when the function is invoked, while parameters are defined by the function itself.

4. Are there any other terms used to refer to arguments and parameters in computer science?

Yes, in some programming languages, arguments are also referred to as actual parameters and parameters as formal parameters. These terms can be used interchangeably with argument and parameter, but the meaning remains the same.

5. Can I use the terms "argument" and "parameter" in other fields besides computer science?

Yes, while these terms have specific meanings in computer science, they can also be used in other fields. In general, an argument refers to a statement or set of statements used to persuade or convince someone, while a parameter can refer to a limit or boundary set for something.

Similar threads

  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
10
Views
3K
  • Programming and Computer Science
Replies
7
Views
4K
  • Programming and Computer Science
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
928
Replies
13
Views
2K
  • Programming and Computer Science
Replies
19
Views
4K
  • Programming and Computer Science
Replies
4
Views
3K
Replies
11
Views
2K
  • Programming and Computer Science
Replies
27
Views
22K
Back
Top