#include <stdio.h>
struct test
{
int a;
};
int main()
{
struct test num;
num.a = 3;
printf("%d\n", num.a);
printf("%d\n", num);
return 0;
}
The output from printf("%d\n", num.a);
in the above code is 3.
And printf("%d\n", num);
below it is also printed as 3.
Here's my question.
How on earth does num
have 3? For me, num.I put the value in a
.
I understand that structure test
serves as a data type, but num
plays a role other than connecting the values of the structure?
printf("%d\n", num.a);
is an example of the normal usage of a structural member variable.
On the other hand, printf("%d\n", num);
is an undefined behavior.
Undefined behavior may have different results depending on the compiler version or compiler manufacturer.
https://en.wikipedia.org/wiki/Undefined_behavior
© 2024 OneMinuteCode. All rights reserved.