Article Directory
variable
- C language identifiers include variables, function names, macro definition, the structure member name.
- C language identifier must be specified in a letter or an underscore
_
at the beginning, it can be followed by a number of letters, numbers, underscores, there can be other characters. - Keywords can not be defined as an identifier.
C language keywords
auto break case char const continue default do double
else enum extern float for goto if int long
register return short signed sizeof static struct switch typedef
union unsigned void volatile while
Type Size
32-bit operating system
#include<iostream>
using std::cout;
using std::endl;
int main()
{
cout <<"char->"<< sizeof(char) << endl;
cout <<"short->"<< sizeof(short) << endl;
cout << "int->"<<sizeof(int) << endl;
cout << "long->"<<sizeof(long) << endl;
cout <<"long long ->"<< sizeof(long long) << endl;
cout << "float->"<<sizeof(float) << endl;
cout << "double->"<<sizeof(double) << endl;
cout << "long float->"<<sizeof(long float) << endl;
cout << "long double->"<<sizeof(long double) << endl;
system("pause");
return 0;
}
char->1
short->2
int->4
long->4
long long ->8
float->4
double->8
long float->8
long double->8
请按任意键继续. . .
64-bit operating system
#include<iostream>
using std::cout;
using std::endl;
int main()
{
cout <<"char->"<< sizeof(char) << endl;
cout <<"short->"<< sizeof(short) << endl;
cout << "int->"<<sizeof(int) << endl;
cout << "long->"<<sizeof(long) << endl;
cout <<"long long ->"<< sizeof(long long) << endl;
cout << "float->"<<sizeof(float) << endl;
cout << "double->"<<sizeof(double) << endl;
cout << "long double->"<<sizeof(long double) << endl;
return 0;
}
char->1
short->2
int->4
long->8
long long ->8
float->4
double->8
long double->16
difference
32-bit long
length of the system is 4,64 bit long
length is 8.
32-bit long float
length is 8,64-bit operating system long float
is not legal data type.
Initialize an array of three characters following differences:
char arr1[]="abc" //'a''b' 'c' '\0'
char arr2[]={'a','b','c'}; //'a''b' 'c'
char *p="abcdef"; //p的内存中只存了字符a的地址
- 1, the memory array is stored in a row.
- 2, a memory cell in the memory (one byte) corresponding to a memory address.
- 3, the 32-bit pointer size is 4 bytes platform, the platform 64 is 8 bytes.
- 4, can be understood as a pointer variable, is specifically designed to store the address of a variable.
% Lf% l and distinction of
C ++ really is very subtle language,% f and% lf for printf () and scanf () effect is different
#include<stdio.h>
int main()
{
float n;
scanf("%lf",&n);
printf("%f",n);
return 0;
}
80
0.000000
Solution: 1) the "% lf" was changed to "% f"; 2) will be replaced by double float
In fact, the printf (), whether or% f% lf, the effect is the same. Because, face float, printf () will float type automatically promoted to double, so it will not have any problems. And, strictly speaking, printf () and no definition of% lf, although many compilers will accept, so it is best to use% f.
For scanf (), by accepting a pointer, and no type of argument upgrade, so it should be used for double% lf, float is% f.