Print Variables
We use the printf()
function to print variables in C programming. We will learn in detail about printing output in later lessons.
For now, let's just see an example to print variables.
#include <stdio.h> int main() { // create a variable int age = 25; // print the variable printf("%d", age); return 0; }
Output
25
The printf()
function prints anything present inside the quotation marks. However, instead of %d
, we are getting 25 (value of the age
variable).
This is because, in C, we use format specifiers to print variables. Format specifiers are placeholders that will be replaced by the value of the variable.
Here, %d
is a format specifier which is replaced by the value of the age
variable (25).
