I'd like to know the format specifier of the C bowl type

Asked 1 years ago, Updated 1 years ago, 66 views

Linux kernel code writes bowl. Is this okay?If you look at From ANSI C99, _Bool or stdbool.h has _Bool Then, where is the format specifier that makes it true/false instead of 1 or 0 output?

bool x = true;
printf("%B\n", x);

Output: true

c printf

2022-09-21 20:32

1 Answers

C supports the boolean type, but there is no format specifier to output true/false. In printf, the format specifier for the bowl is usually %d If you want to print it as true/false, you must specify it separately using a trigonometric operator

bool x = true;
printf("%d\n", x); // 1 output

// To output true or false, select any of the following:
printf(x ? "true" : "false");
//or
printf("%s", x ? "true" : "false");
//or
fputs(x ? "true" : "false", stdout);


2022-09-21 20:32

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.