简体   繁体   中英

What does “%d ->” in printf mean?

I was skimming through this but in line 114 it is written printf("%d -> ", t->value); what I ask is, what does "%d -> mean? Is it a typo or something else?

Example:

struct btnode {
    int value;
    struct btnode * l;
    struct btnode * r;
} * root = NULL, * temp = NULL, * t2, * t1;

void inorder(struct btnode * t) {
    if (root == NULL) {
        printf("No elements in a tree to display");
        return;
    }
    if (t->l != NULL)
        inorder(t->l);
    printf("%d -> ", t->value);
    if (t->r != NULL)
        inorder(t->r);
} 

It's nothing special, just a normal format string.

printf("%d -> ", 42);

outputs:

42 -> 

It means that this piece of code will print the value of t->value in decimal followed by the characters -> . Nothing special, just an ordinary printf

The %d indicates to print a int as described later in the method( t->value ). The -> portion is simply printing -> .

It simply prints a number (%d) followed by an ASCII arrow ->. There's no error.

It is of no special meaning

Since you are using the binary tree concept, to illustrate that the elements are together with the link 在一起

Suppose you have a binary tree already constructed like this one:
               15
              /  \
             10  30
            / \    \
           5  13    35

if you traverse the tree in IN-ORDER then the below printf would print like this:

printf("%d -> ", t->value); 

5 -> 10 -> 13 -> 15 -> 30 -> 35 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM