Declaration method:
Data type variable name;
Example:
// Int type int I;/* General Declaration */int j, k;/* multiple declarations at the same time */int age = 18; /* simultaneous assignment of declarations */int Alan, Sam = 16;/* declaration and simultaneous assignment * // float Type float f;/* Common Declaration */float q, money;/* declare multiple at the same time */float v = 2.0;/* assign a value at the same time * // char c of the char type;/* Common Declaration */char zh, text;/* declare multiple at the same time */char letter = 'a';/* assign values at the same time * // char array (string) char c [20] = {'h', 'E', 'l', 'l', 'O', '', 'w', 'O ', 'R', 'l', 'D'}; char name [] = {'A', 'l', 'A', 'n '};
Escape characters
Characters that must be escaped and cannot appear directly in a string
'\ N' line feed
'\ T' horizontal tabulation
'\ ''Single quotes
'\ "' Double quotation marks
'\' Backslash
#include<stdio.h>main(){ printf("Num\tName\n"); printf("001\tAlan\n"); printf("002\tLellansin\n");}
Output result:
Num Name
001 Alan
002 Lellansin
Printf and scanf
Printf print, scanf is input
Printf (string ,...);
Scanf (string ,...);
For example:
Printf ("Alan's age is % d", age );
Scanf ("% d", & I );
Example:
# Include <stdio. h> main () {int age; printf ("What is your age? \ N "); scanf (" % d ", & age); printf (" your age is % d ", age );}
Common formats:
% D decimal integer
% I decimal integer
% C single character
% S string
% F floating point number