当前位置:网站首页>Embedded C first learning notes

Embedded C first learning notes

2022-06-26 01:16:00 m0_ forty-six million three hundred and twenty-one thousand one

1. An operation ( Binary operation )

(1) And &

If both values are 1 Then for 1, Otherwise 0

(2) or |

If one or both of the two values is 1 Then for 1, All two are 0 by 0

(3) Exclusive or ^

The two bits are different , The result is 1, Otherwise, the result is 0

(4) Take the opposite , Bitwise non ~

Operate on a number , Contraposition ,0 become 1,1 become 0

(5) Move left <<

The data being manipulated << Shifted number , Move left and the right will be empty , repair 0

(6) Move right >>

The number to be manipulated >> Shifted number , Move right and fill left 0, The leftmost digit of the unsigned is 0, The leftmost sign is 1

2. Static variables static

Reference resources :https://blog.csdn.net/guotianqing/article/details/79828100

#include <stdio.h>

void fn(void)
{
    int n = 10;

    printf("n=%d\n", n);
    n++;
    printf("n++=%d\n", n);
}

void fn_static(void)
{
    static int n = 10;

    printf("static n=%d\n", n);
    n++;
    printf("n++=%d\n", n);
}

int main(void)
{
    fn();
    printf("--------------------\n");
    fn_static();
    printf("--------------------\n");
    fn();
    printf("--------------------\n");
    fn_static();

    return 0;
}

 

Running results :

-> % ./a.out 
n=10
n++=11
--------------------
static n=10
n++=11
--------------------
n=10
n++=11
--------------------
static n=11
n++=12

You can find two calls fn_static() Output when n Values change , Instead of using satic Function of ,n The value will not change .

 

3. Global variables extern

about extern function , Used in front of variables . In the variables of each individual file , Use extern Represents that this variable has been defined in other files , You can use variables from other files directly .

Reference material :https://www.cnblogs.com/0zcl/p/6082834.html

 

4. keyword const

const Chinese translation is generally constant , You can modify variables , The pointer , Array , Function parameters, etc .

You can modify variables 、 Array 、 The pointer 、 Function parameter

for example :

const int i = 5;

namely i Read only , Non modifiable , If it is copied again, an error will be reported , It can also be written as int const i = 5;

Reference material :https://baijiahao.baidu.com/s?id=1655909468895829791&wfr=spider&for=pc

 

 

 

原网站

版权声明
本文为[m0_ forty-six million three hundred and twenty-one thousand one]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202180558176301.html