Learning C language fourth day (basic)

sizeof() Calculate the type length
int a=10;
int arr[]={1, 2, 3, 4, 5, 6}; [] is the number of this array and the number can be from the back {} know that
it [number of] which can not write

printf("%d\n",sizeof(a)); This is the size of a is 4 bytes because it is an integer
printf("%d\n",sizeof a); same as the above sizeof() The characters inside can not be written ()
printf("%d\n",sizeof(int)); What is calculated is that the size of the integer is 4 bytes. Here () must write
printf("%d '\n",sizeof(arr)); What is calculated is that the entire size of this array is 24 because a number in it is 4 bytes and 6 numbers are 24 bytes.
printf("%d\n", sizeof( arr)/sizeof(arr[0]) output 6
Learning C language fourth day (basic)

~ Invert by (binary) bit
int a=0 4 bytes 32 bits 000000000000000000000000000000000000000000000000000
The first number in the binary is called the sign bit

int b = ~ ab signed integer, called by the bit inversion of the sign bit is called the foremost + 1 is 0 or 1 - 111111111111111111111111111111111111111111
original code inverse complement code
when the negative is stored in memory, it is stored in binary complement the original code is printed
b binary code on the inside of the front is 1 that it is negative then it is stored when it is complement with
the relationship between the anti-code and anti-complement code is +1 The complement and the inverted code and the original code are inverted but the front number remains unchanged

As long as an integer stored in the memory are in binary complement
integer primary anti-complement three yards uniform
negative is
printf ( "% d", b ) outputs -1

Learning C language fourth day (basic)

++ Pre-add and post-add
int a=10
int b=a++ Post-add and add, use first, then add
printf("a=%db=%d\n",a,b) The output is 11 10

If int b=++a is preceded by ++, add first and then use output 11 11

int b=a---post subtraction output 9 10
int b=--a pre-subtraction output 9 9

(Type) Forced conversion
int a=3.14 int a=(int)3.14
return 0 will report an error, there will be no error, this (int) means that the forced conversion converts 3.14 to an integer

Learning C language fourth day (basic)

The relational operator
<= >=! = == is
used to test for inequality to test for equality

Learning C language fourth day (basic)

Logical operator
&& logical AND
int a=3
int b=5
int c=a&&b a is true b is also true so c is true so output C is equal to 1
|| logical OR

int c=a||ba is true or b is true, c is directly true, and c is 1
Learning C language fourth day (basic)

Conditional operator
exp1?exp2: exp3 This is a whole expression if exp1? If it is true, then the result of exp2 executing it is the result of the entire expression.
This is also a ternary operator. If exp1? If it is false, then the result of exp3 executing it is the result of the entire expression
int a=10
int b=20
int max=0
if (a>b) The thing after if directly becomes like this max=(a>b?a;b )
max=a
else;
max=b
Learning C language fourth day (basic)

The comma expression
exp1, exp2, exp,. . . . expN

Subscript reference function calls and structure members
[] (), ->
int arr[10]={0}
arr[4] Subscript reference operator
int add(int x, int y)
int z=0
z=x+ y
return z
int a=10
int b=20
int sum=add(a,b) called the function add
Learning C language fourth day (basic)

The symbols defined by common keywords cannot conflict with keywords (prescribed)
auto (automatic) break case char const continue default (default) do double else enum extern (introduction of external symbols) float for goto if int long reguster (register) return short signed sizeof static struct (structure keyword) switch typedef (definition) union (union, union) unsigned void volatile while

auto
int a=1 There is an auto in front of it, which means that the integer type a automatically appears in this {} and then disappears automatically. I think there is auto before int, so
break is omitted. It is often used in the loop statement
register register
int a=1 because in the future I will use a frequently, so I want to put it in the register to make it a register variable
register int a=1 At this time, it is only recommended to put a in the register to determine whether it is in the register depends on the compiler.

int defined variable is signed int int and symbols is equivalent to
just signed we usually omitted
if we write unsigned int a = 2 ^ 32 -1 even if it is negative, but because it is so you write unsigned unsigned The number is that it is stored in the original code when it is stored

typedef type definition-type redefinition
unsigned int a=1
can be written as typedif unsigned int u int
u int a=1 from here on, all unsigned int can be directly written as u int
Learning C language fourth day (basic)
static after modification of local variables, the life cycle of local variables becomes longer after modification
after modification modified global variables global variables scope becomes smaller
change the link attribute after modification function is modified from the outside into the internal link attribute link attribute
void Test ()
{
static int. 1 a = a is a static local variable
a ++
the printf ("A=%d\n",a)
int main()
{
int i=0
while (i<5)
{
test()
i++
}
return 0
}

If there is no static, the output is 2 2 2 2 2 With static 2 3 4 5 6
Static local variables mean that they still exist and will not be destroyed after they are out of scope.
Learning C language fourth day (basic)

In the source file inside to build a C ++ in it marked global variables
int a = 10 in another C ++ inside as can be from the same source file
as long as the fight extern int a can use it
in a C ++ inside play is
static int a = 10 then again with another c ++ source file which can not be used
because of reduced static global variables scope

To build the source files inside a C ++ marked with a function Add on the inside ()
in the same source file another C ++ which marked extern int Add () then can use it
and if then build a C ++ source file which marked a function static in it Add ()
after it in the same source file which marked another C ++ extern int Add () can not be used
because the static properties of the function to change the link

define defines the identifier constant
define max 1000
difine can define macros-with parameters
define ADD (x, y) ((x) + (y)) The macro is similar to the function but is different

printf("%p\n", &a) The print address prints out the hexadecimal
int a=10
int p=&a This kind of variable is a pointer used to store the address. The variable
int
is a type
dereference operator
p pair p dereference operation finds the object a pointed to by
p *p=20 turns the value a pointed to by p into 20


There are 2^32 numbered binary numbers in the 32-bit numbered memory, which means that
there are 2^64 numbered binary numbers in the 64-bit number.

If a memory inside a small grid size is the number of bytes it is above that number
int a = 10 a size is 4 bytes then they will take up 4 bytes of memory inside of
which a number of addresses Is the number of the last byte in the 4 bytes

Guess you like

Origin blog.51cto.com/14982478/2545539