-1

In the following C code:

printf( "Coffee!" );

and

 scanf("%d", &coffee); 

 printf("\nI’m baking %d coffee!", coffee); 

Are "Coffee!" and coffee considered arguments?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
zackBYE344
  • 63
  • 5
  • 4
    Well, they are both passed to `printf` as arguments so in that sense, yes they are arguments. Though I'm not confident that is really what you are asking. Maybe turn it around to ask what you think an argument is and is there anything in particular that makes you doubt that those are arguments? – kaylum Jan 27 '22 at 22:12
  • 3
    @zackBYE344 In my point of view they are considered as drinks. – Vlad from Moscow Jan 27 '22 at 22:15
  • 1
    The thing that is passed to a function is an argument. `"\nI’m baking %d coffee!"` is an argument too. A *parameter* of a function is taking the value of the corresponding argument. https://stackoverflow.com/questions/1788923/parameter-vs-argument – Eugene Sh. Jan 27 '22 at 22:17
  • As opposed to what? What else might they be called? Possibly "parameters"? – abelenky Jan 27 '22 at 22:19
  • 1
    @kaylum — your edit wasn't very good. Yes, you indented the code, but in doing so, you left the `*` for (italic) emphasis in the text, which completely screws up the meaning in C. I've removed those formatting stars, but that's made parts of @ryyker's answer inappropriate. The answer critiques stuff that wasn't in the original version of the question. I'm not sure how best to fix this. – Jonathan Leffler Jan 28 '22 at 02:16
  • 1
    @JonathanLeffler - To be more visible, I'll repeat what I said below again here, IMO, you have already _fixed_ what confusion existed. And from what I can guess, although asker has been quiet on the topic, I think the question has been answered sufficiently in comments and in the answers. Thanks! – ryyker Jan 28 '22 at 21:00

2 Answers2

3

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.
Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
2

"Are "Coffee!" and coffee considered Arguments?"

EDITED (in response to corrected original post by Jonathan L.)

Yes, they are both arguments.

  • In the first printf(), "Coffee!" is a single string literal argument.
  • In the second printf() : coffee is the 2nd argument, an int value.
  • And finally it plays a role as the 2nd argument in the scanf() statement as the location to be changed, or in short the address of coffee (&coffee)

Of course this all assumes that coffee was defined similar to;

int coffee = 0; 

Note on arguments and parameters... (mentioned in comments under question)
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)

ryyker
  • 22,849
  • 3
  • 43
  • 87
  • 1
    @kaylum misedited the question, simply indenting the code and not removing the `*` characters that were in the original, unindented code for creating (italic) emphasis. It isn't entirely fair to the OP to critique `*coffee*` because of the misediting. OTOH, now I've removed the inappropriate stars, it isn't entirely fair to you, either; the change invalidates part of your answer. I'm not sure what's the best way to deal with this. I'm open to suggestions — including rolling back my changes to the question. (I'm not sure whether kaylum will get notified about this comment, either.) – Jonathan Leffler Jan 28 '22 at 02:13
  • @JonathanLeffler - Thanks for pointing out the mis-edit in the original post. It did cause a change reaction of sorts, but I do not think any further changes are necessary on your part. I've modified my answer in light of your new (and more accurate) edit of OP. – ryyker Jan 28 '22 at 20:52