Values in C
C has various value types including strings, integers, floats, booleans, etc. Here are a few basic examples.
To compile and run this C program:
In this C version:
- We use
printf
instead of fmt.Println
for output. - Strings in C are character arrays, so we can’t directly concatenate them with
+
. Instead, we print them separately. - C doesn’t have a built-in boolean type. We use integers (0 for false, non-zero for true) and include
<stdbool.h>
for boolean operations. - The
%d
format specifier is used for integers, and %f
for floats in printf
. - In C, the
main
function typically returns an integer, so we include return 0;
at the end.
This example demonstrates basic value types and operations in C, including string output, integer and float arithmetic, and logical operations.