繁体   English   中英

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

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

我浏览了一下,但在第114行中将其写为printf("%d -> ", t->value); 我要问的是, "%d ->是什么意思?是错别字还是其他?

例:

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);
} 

没什么特别的,只是普通格式的字符串。

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

输出:

42 -> 

这意味着这段代码将以十进制打印t->value ,后跟字符-> 没什么特别的,只是普通的printf

%d表示要打印int,如稍后在method( t->value )中所述。 ->部分只是打印->

它只打印一个数字(%d),后跟一个ASCII箭头->。 没有错

没有特别的意义

由于您使用的是二叉树概念,因此可以说明元素与链接绑定在一起

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

如果以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