我的练习是使用一个结构来初始化值然后打印它们(听起来很简单)但是我们必须使用指针 *p 而不是使用结构来打印它们。我知道这可能有一个非常简单的答案,但我们将不胜感激!
#include <stdio.h>
#include <string.h>
struct info
{
int total;
char *str;
};
int main()
{
struct info s, *p = &s;
s.total = 50;
s.str = "hello";
printf("Info total: %i\n", s.total);
printf("Info *str: %s\n", s.str);
return 0;
}
最佳答案
s.total <=> p->total or (*p).total
感谢大家的回答!
关于c - 如何在 C 中使用指针打印带有结构的变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33311998/