In the following C code:
printf( "Coffee!" );
and
scanf("%d", &coffee);
printf("\nI’m baking %d coffee!", coffee);
Are "Coffee!" and coffee considered arguments?
CodePudding user response:
"Are "Coffee!" and coffee considered Arguments?"
Not exactly, but close...
First - the following assumes that coffee has been defined;
int coffee = 0;
`"coffee"` would be a correct argument in the first `printf()` statement, but what your code shows: `*"Coffee!"*` although intended as an argument, would not work.
Then later, in the following:
scanf("%d", &coffee); //&coffee is considered the argument, not just coffee
// printf("\nI’m baking %d coffee!", *coffee*);//*coffee* is incorrect
printf("\nI’m baking %d coffee!", coffee);//coffee is correct
The prototype for printf() being:
Where in the scanf() statement, both "%d" and &coffee are arguments.
And in the printf() statement both "\nI’m baking %d coffee!" and coffee are arguments .
Note on arguments and parameters... When a function is called, the values that are passed during the call are referred to as arguments. The values which are used to define the type of argument used in a function prototype are referred to as parameters. (reference)
CodePudding user response:
You have provided one argument to the first call to printf(), and you have provided two arguments to the call to scanf() and two more to the second call to printf().
The C standard defines both 'argument' and 'parameter':
- §3.3 argument
actual argument
actual parameter (deprecated)
expression in the comma-separated list bounded by the parentheses in a function call expression, or a sequence of preprocessing tokens in the comma-separated list bounded by the parentheses in a function-like macro invocation. - §3.16 parameter
formal parameter
formal argument (deprecated)
object declared as part of a function declaration or definition that acquires a value on entry to the function, or an identifier from the comma-separated list bounded by the parentheses immediately following the macro name in a function-like macro definition.
