0
#include <stdio.h>

int main(void)

{

    int ten = 10;

    int two = 2;



    printf("Doing it right: ");

    printf("%d minus %d is %d\n", ten, 2, ten - two );

    printf("Doing it wrong: ");

    printf("%d minus %d is %d\n", ten );  // forgot 2 arguments



    return 0;

}

hello actually i coulnt understand the lines here 

  printf("%d minus %d is %d\n", ten );  // forgot 2 arguments

they do not define arguments over here

3
Contributors
2
Replies
6
Views
4 Years
Discussion Span
Last Post by Lucaci Andrew
0

An argument is also called a parameter, if you've heard that before? An argument is a piece of data passed to a function to be used within that function. In the case of printf, the format string, the first argument, specifies three '%d' markers, which indicate to printf that there will be three arguments to follow, and these should be placed at these markers in the order they were supplied in the function.

0

Try this:

#include <stdio.h>
int main(void)
{
    int ten = 10;
    int two = 2;
    printf("Doing it wrong: ");
    printf("%d minus %d is %d\n", ten );  // forgot 2 arguments
    printf("Doing it right: ");
    printf("%d minus %d is %d\n", ten, 2, ten - two );
    return 0;
}

and see if the answer is the same.
On compiation time it should give you some warnings, as:
"warning: format '%d' expects a matching 'int' argument [-Wformat]"

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.