scanf——格式化输入说明

scanf格式说明符遵循以下原则:

%[*][width][length]specifier

specifier Description Characters extracted
i Integer Any number of digits, optionally preceded by a sign (+ or -).
Decimal digits assumed by default (0-9), but a 0 prefix introduces octal digits (0-7), and0x hexadecimal digits (0-f).
Signed argument.
d or u Decimal integer Any number of decimal digits (0-9), optionally preceded by a sign (+ or -).
d is for a signed argument, and u for an unsigned.
o Octal integer Any number of octal digits (0-7), optionally preceded by a sign (+ or -).
Unsigned argument.
x Hexadecimal integer Any number of hexadecimal digits (0-9, a-f, A-F), optionally preceded by 0x or 0X, and all optionally preceded by a sign (+ or -).
Unsigned argument.
f, e, g Floating point number A series of decimal digits, optionally containing a decimal point, optionally preceeded by a sign (+ or -) and optionally followed by the e or E character and a decimal integer (or some of the other sequences supported by strtod).
Implementations complying with C99 also support hexadecimal floating-point format when preceded by 0x or 0X.
a
c Character The next character. If a width other than 1 is specified, the function reads exactly widthcharacters and stores them in the successive locations of the array passed as argument. No null character is appended at the end.
s String of characters Any number of non-whitespace characters, stopping at the first whitespace character found. A terminating null character is automatically added at the end of the stored sequence.
p Pointer address A sequence of characters representing a pointer. The particular format used depends on the system and library implementation, but it is the same as the one used to format %pin fprintf.
[characters] Scanset Any number of the characters specified between the brackets.
A dash (-) that is not the first character may produce non-portable behavior in some library implementations.
[^characters] Negated scanset Any number of characters none of them specified as characters between the brackets.
n Count No input is consumed.
The number of characters read so far from stdin is stored in the pointed location.
% % A % followed by another % matches a single %.

http://www.cplusplus.com/reference/cstdio/scanf/

printf——格式化输出说明

printf格式说明符遵循以下原则:

%[flags][width][.precision][length]specifier

%[标志][宽度][.精度][长度]说明符

specifier Output Example
d or i 带符号的十进制整数 392
u 无符号的十进制整数 7235
o 无符号八进制数字 610
x 无符号十六进制整数 7fa
X 无符号十六进制整型(大写) 7FA
f 十进制浮点数,小写 392.65
F 十进制浮点数,大写 392.65
e Scientific notation (mantissa/exponent), lowercase 3.9265e+2
E Scientific notation (mantissa/exponent), uppercase 3.9265E+2
g Use the shortest representation: %e or %f 392.65
G Use the shortest representation: %E or %F 392.65
a Hexadecimal floating point, lowercase -0xc.90fep-2
A Hexadecimal floating point, uppercase -0XC.90FEP-2
c 字符 a
s 字符串 sample
p 指针地址 b8000000
n Nothing printed.
The corresponding argument must be a pointer to a signed int.
The number of characters written so far is stored in the pointed location.
% A % followed by another % character will write a single % to the stream. %

http://www.cplusplus.com/reference/cstdio/printf/

二进制与十六进制相关问题

bit(二进制位)是计算机中的最小单位。

1字节=8bit

8个二进制数占1字节。

2个十六进制数占1字节。

int声明的变量占4个字节。

 

二进制最高位表示正负。其中,0表示正、1表示负。

十六进制数最高位大于等于8时,必然是负数。

使用unsigned int声明变量时,不考虑符号,只取0和正数。

 

argc:arg为参数,c为计数器。

argv:arg为参数,v为值(value)

char:字符。占用1字节,8个位。

 

#include <stdio.h>

int main(int argc, char *argv[])
{
	int a = 0xFFFFFFFF;
	int b = 0x0FFFFFFF;

	printf("%d\t%u\n", a,a);
	printf("%d", b);

	return 0;
}

 

 

编译、编译器与集成开发环境

一、编译

编译是指把高级语言转化为机器语言的动作。

二、编译器

Windows平台——cl

Linux平台——gcc

Mac平台——clang

三、常见的集成开发环境

Windows平台——Visual Studio

Mac平台——Xcode

跨平台编译——Eclipse、Eclipse+CDT(开发C、C++)、CLion