简体   繁体   English

printf中的“%d->”是什么意思?

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

I was skimming through this but in line 114 it is written printf("%d -> ", t->value); 我浏览了一下,但在第114行中将其写为printf("%d -> ", t->value); what I ask is, what does "%d -> mean? Is it a typo or something else? 我要问的是, "%d ->是什么意思?是错别字还是其他?

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 -> . 这意味着这段代码将以十进制打印t->value ,后跟字符-> Nothing special, just an ordinary printf 没什么特别的,只是普通的printf

The %d indicates to print a int as described later in the method( t->value ). %d表示要打印int,如稍后在method( t->value )中所述。 The -> portion is simply printing -> . ->部分只是打印->

It simply prints a number (%d) followed by an ASCII arrow ->. 它只打印一个数字(%d),后跟一个ASCII箭头->。 There's no error. 没有错

It is of no special meaning 没有特别的意义

Since you are using the binary tree concept, to illustrate that the elements are Bind 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: 如果以IN-ORDER遍历树,则下面的printf将像这样打印:

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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