Are words argument and parameter interchangeable cs

AI Thread Summary
In C++, the terms "argument" and "parameter" are not interchangeable, as they refer to different concepts; an argument is the actual value passed to a function, while a parameter is the variable defined in the function declaration. The function `int main()` serves as the entry point of a C++ program, and while it can take parameters from command line arguments, it does not require them. Unlike mathematical functions, C++ functions may not always return values, with non-returning functions referred to as "void functions." The use of `void main()` is considered non-standard in C++, and the correct declaration should always return an integer. Understanding these distinctions is crucial for beginners in programming.
PainterGuy
Messages
938
Reaction score
72
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:
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...
Back
Top