CodeNest

Variables and printf

C is statically typed: you declare the type of every variable.

int count = 3;
float price = 2.5f;
double precise = 3.14159;
char letter = 'A';

printf uses format specifiers to insert values:

SpecifierTypeExample
%dintprintf("%d", 42);
%ffloat/doubleprintf("%.2f", 2.5);2.50
%ccharprintf("%c", 'A');
%sstringprintf("%s", "hi");

Try it

Print the number of apples and the total price (12 × 0.5) with two decimals:

Apples: 12
Total: 6.00
C unavailable
Next
Running C needs a server execution engine, which isn't configured on this deployment. You can still read the lesson and try the code locally.
Loading editor…

Press Ctrl/ + Enter or click Run to see the output here.