PainterGuy said:
hello everyone,
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.