C examples for Language Basics:Hello World
printf function can print values and variables to the console window.
#include <stdio.h> int main() { int x = 5; printf("x is %d and 2+3 is %d", x, 2+3); }
The %d specifier displays an integer of the char, short or int type.
Other commonly used format specifiers are seen in the following table.
Specifier | Output |
---|---|
%d or %i | char, short, or int |
%c | character |
%s | string of characters |
%f | float or double |
%Lf | long double |
%ld | long int |
%lld | long long int |
%u | unsigned char, short or int |
%lu | unsigned long int |
%llu | unsigned long long int |
%p | pointer address |