zoukankan      html  css  js  c++  java
  • STM32——C语言课堂原代码

    指针
    1 /* 2 ============================================================================ 3 Name : Hello.c 4 Author : 5 Version : 6 Copyright : Your copyright notice 7 Description : Hello World in C, Ansi-style 8 ============================================================================ 9 */ 10 11 #include <stdio.h> 12 #include <stdlib.h> 13 void reset(int i); 14 void reset2(int* p); 15 void add_by_point(int x,int y,int *result); 16 int main(void) { 17 18 printf("%d ",sizeof(char)); 19 printf("%d ",sizeof(int)); 20 int a = 10; 21 int *p1 = &a; 22 char *p2 = p1; 23 24 printf("%d ",p1); 25 printf("%d ",p2); 26 27 printf("%d ",*p1);//10 28 printf("%d ",*p2); 29 30 puts("----------------------"); 31 int c[10] = { 32 1,2,3,4,5 33 }; 34 //数组内容值默认为0 (一组数组a定义10个变量,前5个分别是1,2,3,4,5,那么后六个默认为0) 35 printf("%d ",c[5]); 36 //数组名也是数字首地址(数组名的地址和首个数字的地址一样,比喻:一栋5层楼相当于一组数组,1层、2层、3层、4层、5层相当于变量的地址,那么的地址这栋楼的地址与第一层楼的地址一样。) 37 printf("%d ",c); 38 //指针运算要根据指针的类型(int、float的字节是4个,char的字节是1个,i例如:int类型的a的地址是1,那么a+1的地址是5,如果a类型是char,则a+1的地址是2) 39 printf("%d ",c+1); 40 // 41 printf("%d ",*(c+2));//带*的是求地址里面的内容 42 *(c+2) = 0; 43 printf("%d ",*(c+2)); 44 45 puts("----------------------"); 46 int d = 10; 47 reset(d); 48 //函数独立性 49 printf("%d ",d); 50 reset2(&d); 51 //使用指针的方式突破函数壁垒 52 printf("%d ",d); 53 54 //什么是返回值 55 int e = add(3,5); 56 printf("e = %d ",e); 57 int result = 0; 58 //指针的方式计算结果 59 add_by_point(3,5,&result); 60 printf("result = %d ",result); 61 62 } 63 void reset(int i){ 64 i = 0; 65 } 66 void reset2(int* p){ 67 *p = 0; 68 } 69 70 71 int add(int i,int j ){ 72 /* 73 * 变量的生命周期 74 * 75 * */ 76 77 int q = i+j; 78 return q; 79 } 80 81 void add_by_point(int x,int y,int *result){ 82 int r = (x + y); 83 *result = r; 84 }


    /*
     ============================================================================
     Name        : hello.c
     Author      : lei
     Version     : 137
     Copyright   : Your copyright notice
     Description : Hello World in C, Ansi-style
     ============================================================================
     */
    
    #include <stdio.h>
    #include <stdlib.h>
    
    int main(void) {
    
        main2();
        return 0;
        puts("!!!Hello World!!!"); /* prints !!!Hello World!!! */
    
        int i = 10;
        reset(i);
        printf("%d
    ",i);
        reset2(&i);
        printf("%d
    ",i);
    
    
        int a = 10;
        int b = &a;
        *(int*)b = 0;
    
    
        printf("%d
    ",a);
    
        int *p;
        p=b;//p相当于(int*)b
        *p = 4;
        printf("%d
    ",a);
    
        /*
        int c = 0x22336655;
        int *d = &c;
        *d = 1;
        */
    
        char aa = 1;
        printf("%d
    ",&aa);
    
        return EXIT_SUCCESS;
    }
    
    
    void reset(int i){
        i = 0;
    }
    
    void reset2(int *p){
        *p = 0;
    }

     http://download.csdn.net/album/detail/1111

    枚举

     1 /*
     2  * meiju.c
     3  *
     4  *  Created on: 2017年9月15日
     5  *      Author: Administrator
     6  *      137
     7  */
     8 
     9 enum COLOR {
    10         RED,YELLOW,BLUE,GREEN
    11     };
    12 
    13 int favorate_color = RED;
    14 void main2(){
    15 
    16     puts("---------------------");
    17     //枚举内容默认值从0开始,逐步加1
    18     printf("%d
    ",RED);
    19     printf("%d
    ",YELLOW);
    20     printf("%d
    ",BLUE);
    21     puts("---------------------");
    22     //枚举内容根据前面的那一个值加1
    23     printf("%d
    ",RED);
    24         printf("%d
    ",YELLOW);
    25         printf("%d
    ",BLUE);
    26 
    27         set_favorate_color(BLUE);
    28 
    29         printf("favorate_color = %d
    ",favorate_color);
    30 
    31 }
    32 
    33 
    34 void set_favorate_color(int color){
    35     favorate_color = color;
    36 
    37 }

     机房内容

     1 /*
     2  ============================================================================
     3  Name        : xu.c
     4  Author      : xu
     5  Version     :
     6  Copyright   : Your copyright notice
     7  Description : Hello World in C, Ansi-style
     8  ============================================================================
     9  */
    10 
    11 #include <stdio.h>
    12 #include <stdlib.h>
    13 
    14 int main(void) {
    15     puts("Hello UPC World"); /* prints Hello UPC World */
    16     return EXIT_SUCCESS;
    17 
    18 int a = 0;//定义变量a,赋值为1
    19 int *p = &a;//定义一个指针,这个指针的内容是变量a的地址
    20 *p = 1;//*P是里面的内容,内容是变量a的地址,把1赋值给P*就是修改a的地址
    21 
    22 int b = &b;//定义一个b变量,内容是b的地址
    23 *(int*)b = 2;//b是变量,(int*)b是把变量b强制转换为地址,*(int*)b是(int*)b地址的内容,也就是改变量b里面的内容
    24 
    25 puts("----------------------");
    26 enum COLOR {
    27     red,bule=3,yellow,green
    28 };
    29 //枚举的特性
    30 }
    31 
    32 void reset1(int i)
    33 {
    34     i = 0;
    35 }
    36 void reset2(int *i)
    37 {
    38     *i = 0;
    39 }
    40 void reset3(int i)
    41 {
    42     *(int*)i = 0;
    43 
    44 }
  • 相关阅读:
    perl 函数 左值属性
    JavaReflectionManager cannot be cast to org.hibernate.annotations.common.reflection.MetadataProvider
    org/aspectj/weaver/reflect/ReflectionWorld$ReflectionWorldException : Unsupported major.minor versio
    Element 'property' cannot have character [children], because the type's content type is element-only
    java.lang.UnsupportedClassVersionError: org/hibernate/cfg/Configuration : Unsupported major.minor v
    Caused by: org.xml.sax.SAXParseException: The prefix "aop" for element "aop:config" is not bound
    org.hibernate.ObjectNotFoundException: No row with the given identifier exists
    Caused by: java.lang.IllegalStateException: SpringJUnit4ClassRunner requires JUnit 4.12 or higher
    如何引导企业数据“价值变现”,看能源化工业的数据化管理
    如何引导企业数据“价值变现”,看能源化工业的数据化管理
  • 原文地址:https://www.cnblogs.com/kinson/p/7513671.html
Copyright © 2011-2022 走看看