“%3d”代表什么?在printf语句中意味着什么? [英] What does "%3d" mean in a printf statement?

查看:688
本文介绍了“%3d”代表什么?在printf语句中意味着什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在此代码中,符号%3d 的作用是什么?我知道%表示引用变量。

In this code what is the role of the symbol %3d? I know that % means refer to a variable.

这是代码:

#include <stdio.h>
int main(void)
{
    int t, i, num[3][4];
    for(t=0; t<3; ++t)
        for(i=0; i<4; ++i)
            num[t][i] = (t*4)+i+1;
    /* now print them out */
    for(t=0; t<3; ++t) {
        for(i=0; i<4; ++i)
            printf("%3d ", num[t][i]);
        printf("\n");
    }
    return 0;
}


推荐答案

%3d 可以细分如下:


  • 表示在此处打印变量

  • 3 表示至少使用3个空格进行显示,并根据需要填充
  • d 表示变量将是整数

  • % means "Print a variable here"
  • 3 means "use at least 3 spaces to display, padding as needed"
  • d means "The variable will be an integer"

将它们放在一起,意味着打印一个整数,最少占用3个空格

Putting these together, it means "Print an integer, taking minimum 3 spaces"

请参见 http://www.cplusplus.com/reference/clibrary/cstdio/printf/ 了解更多信息

这篇关于“%3d”代表什么?在printf语句中意味着什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆