Variables in C
Our first program will demonstrate how to declare and use variables in C. Here’s the full source code:
In C, variables are explicitly declared and used by the compiler to check type-correctness of function calls and operations.
char*
declares a string (character pointer) variable.
You can declare multiple variables of the same type in one line.
C doesn’t have a built-in boolean type, but we can use #include <stdbool.h>
to get the bool
type.
Variables declared without initialization in C are not guaranteed to have a “zero value”. It’s good practice to initialize them explicitly.
C doesn’t have a shorthand syntax for declaring and initializing variables. You always use the standard declaration syntax.
To compile and run the program:
This program demonstrates basic variable declaration and usage in C. Remember that C is a statically-typed language, so you need to declare the type of each variable explicitly.