Search code examples
ctypesprintfconversion-specifier

What (%f) means in C?


I know that %f means float, althought, I don't know if the brackets make any difference. I have this:

void print_LIST(LIST L){
    CORD *c;
    while(L != NULL){
        c = L->value;
        printf("%d%d",c->col,c->lin);
        printf("(%f) ",distance(c));
        L = L->next;
    }
    printf("\n");
}

Solution

  • Not everything in a format specifier is a conversion specifier (carry special meaning). For example: assuming i holds a value of 10, following statement:

     printf ("The value of i is %d", i);
    

    will print The value of i is 10, so the rest of the string is printed as-is. Following this, in your case

     printf ("(%f)", distance(c));
    

    will print the double value returned by the distance(c) function call. Assuming a value 1.23, it will print (1.23) (with the parenthesis).