我们如何将其布置在表格中,以便地址值和名称出现在适当的行和列中?
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
int main() {
int tuna = 20;
printf("Adress \t Name \t Value \n");
printf("%p \t %s \t %d \n",&tuna , "tuna", tuna);
int * pTuna = &tuna;
printf("%p \t %s \t %d \n", pTuna, "tuna", tuna);
printf("%p \t %s \t %p \n", &pTuna, "tuna", pTuna);
_getch();
return 0;
}
最佳答案
我修改了您的程序,如下所示。在这里,%-15
确保以15个字符的字段以左缩进打印数据。当然,我在这里假设的数据将适合15个字符的字段。您可能需要根据需要进行更改。
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
int main() {
int tuna = 20;
printf("%-15s %-15s %-15s \n","Address","Name","Value");
printf("%-15p %-15s %-15d \n",&tuna , "tuna", tuna);
int * pTuna = &tuna;
printf("%-15p %-15s %-10d \n", pTuna, "tuna", tuna);
printf("%-15p %-15s %-15p \n", &pTuna, "tuna", pTuna);
_getch();
return 0;
}
和我得到的输出:
Address Name Value
0xbffff510 tuna 20
0xbffff510 tuna 20
0xbffff50c tuna 0xbffff510
我希望这是您想要的。
关于c - 如何在c中创建此给定代码的表?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32918828/