• C与C++中的常用符号与标点用法详解及实例


    C与C++中的常用符号与标点符号有:“+”、“-”、“*”、 “/”、“%”、“&”、“\”、“|”、“~”、“^”、“&”、“|”、“!”、“>”、“<”、"="、“#”、“?”、“,”、“.”、“:”、单引号、双引号、大括号、中括号、小括号。这些符号与标点经过组合还可形成代表特定功能与操作的符号。

    一 赋值运算符

         赋值运算符为等号,示例:

         int a;

          a = 10;//将值10赋予变量a 

    二  四则运算与取模

    四则运算符包含加、减、乘、除。分别用到“+”、“-”、“*”、 “/”符号。示例:

    1. int t1, t2, t3,t4;
    2. t1 = t1 + t2;
    3. t1 = t3 - t2;
    4. t1 = t2 * t3;
    5. t1 = t2 / t4;

    取模即求两个整数向除的余数,使用的符号为“%”,注意:浮点数不可取模。示例:

    1. #include <iostream>
    2. using namespace std;
    3. int t1;
    4. int t2;
    5. int main()
    6. {
    7. t1 = 10;
    8. t2 = 3;
    9. cout << t1 % t2<< endl;
    10. cout << endl;
    11. }

    运行结果如下:

    修改程序,添加一个浮点变量,如下:

    1. #include <iostream>
    2. using namespace std;
    3. int t1;
    4. int t2;
    5. float t3 = 3.0;
    6. int main()
    7. {
    8. t1 = 10;
    9. t2 = 3;
    10. cout << t1 % t2<< endl;
    11. cout << endl;
    12. cout << t1 % t3 << endl;
    13. cout << endl;
    14. }

    点击生成,结果如下:

     说明浮点数不能取模。

            四则运算符及取模符与等号组合: +=, -=,*=, /=, %=。其所表达的意义是:将右边表达式的值与左边变量的值进行运算,然后再将结果赋值给左边变量。 示例程序:

           

    1. #include <iostream>
    2. using namespace std;
    3. int t1 = 10;
    4. int t2 = 3;
    5. float t3 = 3.0;
    6. int main()
    7. {
    8. t1 *= t3;
    9. cout <<"t1 = " << t1 << endl;
    10. t1 -= 5;
    11. cout << "t1 = " << t1 << endl;
    12. t1 += 7;
    13. cout << "t1 = " << t1 << endl;
    14. t1 %= t2;
    15. cout << "t1 = " << t1 << endl;
    16. t1 += 11;
    17. t1 /= t2;
    18. cout << "t1 = " << t1 << endl;
    19. cout << endl;
    20. t3 *= t1 * t2 % 7;
    21. cout << "t3 = " << t3 << endl;
    22. return 0;
    23. }

    运行结果如下:

     连续两个除号,在C及C++中被用作单行行注释符,即如果程序的某行中如果含有//,该行中//后面的内容在程序编译时被忽略,不被编译。除号与乘号组合构成多行块注释符注释符:/*   */。程序中包含在/*   */中的内容在程序编译时被忽略,不被编译。注释示例:

    1. typedef struct
    2. {
    3. STC32G_IOPORT port; //I/O port
    4. ui8 pins; //I/O pins
    5. STC32G_IOMODE mode; // I/O mode
    6. BOOL pullUpEnable; //pull up enable/disable
    7. BOOL pullDownEnable; //Pull down enable/disable
    8. BOOL drvEn; //driving ability enhance enable/disable
    9. BOOL speedHi; // I/O speed high/normal
    10. BOOL dIEnable; // digtal signal input enable/disable
    11. BOOL sTEnable; //schmitt trigger enable/disable
    12. }STC32G_IOTypeDef;
    13. /****************************************
    14. Function: STC32G_IOInitDef(STC32G_IOTypeDef* pstruct);
    15. Return value: void
    16. mstruct: address of struct to init to default
    17. description: init STC32G_IOTypeDef struct to default exclude port and pins
    18. Example:
    19. STC32G_IOTypeDef* pstruct;
    20. STC32G_IOInitDef(pstruct);
    21. ****************************************/
    22. void STC32G_IOInitDef(STC32G_IOTypeDef* pstruct);

    在字符串中除号(/)为转义符,在字符串格式化函数中取模运算符的意义为替代指示符。示例:

    1. #include <iostream>
    2. using namespace std;
    3. int t1 = 10;
    4. int t2 = 3;
    5. double t3 = 3.0;
    6. char temp[20] = "";
    7. int main()
    8. {
    9. t1 *= t3;
    10. sprintf_s(temp, "t1 = %d\n", t1);
    11. cout << temp;
    12. t1 -= 5;
    13. sprintf_s(temp, "t1 = %d\n", t1);
    14. cout << temp;
    15. t1 += 7;
    16. sprintf_s(temp, "t1 = %d\n", t1);
    17. cout << temp;
    18. t1 %= t2;
    19. sprintf_s(temp, "t1 = %d\n", t1);
    20. cout << temp;
    21. t1 += 11;
    22. t1 /= t2;
    23. sprintf_s(temp, "t1 = %d\n", t1);
    24. cout << temp;
    25. t3 *= t1 * t2 % 7;
    26. sprintf_s(temp, "t1 = %.2f\n", t3);
    27. cout << temp;
    28. sprintf_s(temp, "%s\n", "Hello world!");
    29. cout << temp;
    30. return 0;
    31. }

    运行结果如下:

    乘号(*)的另以重要作用为指针定义及访问指针指向地址中的数据。示例:

    int a = 10;

    int *pInt;

    pInt = &a;

    *pInt = 20;

     加号(+)连用,组成++运算符。 减号(-)连用,组成--运算符;++运算符为自加运算,即变量值加1后再赋值给原变量。--运算符为自减运算,即变量值减1后再赋值给原变量。++运算符与--运算符既可放在变量的左边,有可放在变量的右边,但二者表达的意义完全不一样。如果放在变量的左边,是在变量完成自加或自减运算后再参与表达式的运算。如果放在变量的右边,则是在变量参与表达式的运算完成后再进行自加或自减运算。实例:

    1. #include <iostream>
    2. using namespace std;
    3. int t1 = 10;
    4. int t2 = 3;
    5. double t3 = 3.0;
    6. char temp[20] = "";
    7. int main()
    8. {
    9. t1 = t2++ * 10;
    10. sprintf_s(temp, "t1 = %d\n", t1);
    11. cout << temp;
    12. sprintf_s(temp, "t2 = %d\n", t2);
    13. cout << temp;
    14. t1 = ++t2 * 10;
    15. sprintf_s(temp, "t1 = %d\n", t1);
    16. cout << temp;
    17. sprintf_s(temp, "t2 = %d\n", t2);
    18. cout << temp;
    19. t1 = t2-- * 10;
    20. sprintf_s(temp, "t1 = %d\n", t1);
    21. cout << temp;
    22. sprintf_s(temp, "t2 = %d\n", t2);
    23. cout << temp;
    24. t1 = --t2 * 10;
    25. sprintf_s(temp, "t1 = %d\n", t1);
    26. cout << temp;
    27. sprintf_s(temp, "t2 = %d\n", t2);
    28. cout << temp;
    29. t1 = t3++ * 10;
    30. sprintf_s(temp, "t1 = %d\n", t1);
    31. cout << temp;
    32. sprintf_s(temp, "t3 = %f\n", t3);
    33. cout << temp;
    34. t1 = ++t3 * 10;
    35. sprintf_s(temp, "t1 = %d\n", t1);
    36. cout << temp;
    37. sprintf_s(temp, "t3 = %f\n", t3);
    38. cout << temp;
    39. t1 = t3-- * 10;
    40. sprintf_s(temp, "t1 = %d\n", t1);
    41. cout << temp;
    42. sprintf_s(temp, "t3 = %f\n", t3);
    43. cout << temp;
    44. t1 = --t3 * 10;
    45. sprintf_s(temp, "t1 = %d\n", t1);
    46. cout << temp;
    47. sprintf_s(temp, "t3 = %f\n", t3);
    48. cout << temp;
    49. return 0;
    50. }

     运行结果如下:

    减号与大于符号组合用于结构体指针及类指针访问成员变量(或函数)。示例:

    1. //*****************************************************************************************
    2. void STC32G_IOInitDef(STC32G_IOTypeDef* pstruct)
    3. {
    4. pstruct -> mode = BI_IO; //bidirectional I/O
    5. pstruct -> pullUpEnable = 0; //pull up disable
    6. pstruct -> pullDownEnable = 0; //pull down disable
    7. pstruct -> drvEn = 0; //drive ability enhance disable
    8. pstruct -> speedHi = 0; //level cnvert speed low
    9. pstruct -> dIEnable = 1; //digital signal input enable
    10. pstruct -> sTEnable = 1; //schmitt trigger enable
    11. }
    12. //End of STC32G_IOInitDef(STC32G_IOTypeDef* pstruct)

     三 比较运算符

    比较运算符包含等于:==、大于:>、大于等于:>=、小于:<、小于等于:<=。比较运算常用用于条件执行语句中。示例:

    1. #include <iostream>
    2. using namespace std;
    3. int t1 = 10;
    4. int t2 = 4;
    5. double t3 = 7;
    6. char temp[20] = "";
    7. int main()
    8. {
    9. if(t1 > t2 && t1 > t2)
    10. cout <<"t1 is maxiuam"<<endl;
    11. else
    12. cout << "t1 is not maxiuam" << endl;
    13. if (t1 > t3 || t1 < t3)
    14. cout << "t1 is not equal t3" << endl;
    15. else
    16. cout << "t1 equal t3" << endl;
    17. t3 = 10;
    18. if (t1 > t3 || t1 < t3)
    19. cout << "t1 is not equal t3" << endl;
    20. else
    21. cout << "t1 equal t3" << endl;
    22. if (t1 <= t2 )
    23. cout << "t1 is not more than t2" << endl;
    24. else
    25. cout << "t1 is more than t2" << endl;
    26. if (t1 >= t2)
    27. cout << "t1 is not less than t2" << endl;
    28. else
    29. cout << "t1 is less than t2" << endl;
    30. return 0;
    31. }

    运行结果:

     四 逻辑运算符

    逻辑运算包含:与(&&)、或(||)、非(!)。 逻辑运算多用于条件语句中,比较运算符示例中已用到过逻辑与与逻辑或,这里不再演示。逻辑示例:

    1. //***********************************************************************
    2. void Uart1_SendByte(BYTE mData)
    3. {
    4. TI = 0;
    5. SBUF = mData;
    6. while(!TI);
    7. //TI = 0;
    8. }
    9. //End of Uart1_SendByte(BYTE mData)

    五 位运算符

    位运算符包含移位运算符与位逻辑运算符。

    位运算符

    包含按位与(&)、按位或(|)、按位取反(~)、按位异或(^)。

    移位运符

    算包含左移与右移运算符。这两个运算符与C++ iostrem库中的cin、cout后面的输入、输出符一致,两个小于(大于)符号连在一起。

    左移运算符:<< 。左移一位,被移位数乘以2

    右移运算符:>>。右移一位,被移位数除以2

    位操作在嵌入式编程,如单片机编程中应用较多,用于对寄存器的位操作,如置位与复位。示例:

    1. //***********************************************************************/
    2. BYTE SetBit(BYTE* pBYTE, BITPOS bPos)
    3. {
    4. *pBYTE |= 1 << bPos;
    5. return *pBYTE;
    6. }
    7. //End of SetBit(BYTE* pBYTE, BITPOS bPos)
    8. //***********************************************************************/
    9. BYTE ResetBit(BYTE* pBYTE, BITPOS bPos)
    10. {
    11. *pBYTE &= ~(1 << bPos);
    12. return *pBYTE;
    13. }
    14. //End of ResetBit(BYTE* pBYTE, BITPOS bPos)
    15. //***********************************************************************/
    16. BYTE ReplaceBits(BYTE* pBYTE,BITPOS hBit,BITPOS lBit,BYTE mData)
    17. {
    18. ui8 tem = hBit - lBit + 1;
    19. tem = (1 << tem) - 1;
    20. mData &= tem; //discard bits may be redundant
    21. *pBYTE &= ~(tem << lBit); //clear specified bits
    22. *pBYTE |= (mData << lBit); //set specified bits
    23. return *pBYTE;
    24. }
    25. //End of ReplaceBits(BYTE* pBYTE,BITPOS hBit,BITPOS lBit,BYTE mData)

    按位异或可实现bit位的1位或多位取反。示例:

    1. #include <iostream>
    2. #include <stdio.h>
    3. #include <stdlib.h>
    4. using namespace std;
    5. char t1 = 0xFF;
    6. char t2 = 0xF0;
    7. unsigned char temp[20] = "";
    8. typedef unsigned char ui8;
    9. ui8* UcharBToString(ui8 src, ui8* desString)
    10. {
    11. ui8 i;
    12. memset(desString, 0, 20);
    13. for (i = 0; i < 8; i++)
    14. {
    15. if ((src << i) & 0x80)
    16. desString[i] = '1';
    17. else
    18. desString[i] = '0';
    19. }
    20. return desString;
    21. }
    22. int main()
    23. {
    24. t1 ^= 0xFF;
    25. UcharBToString(t1, temp);
    26. cout << temp << endl;
    27. t1 = 0xFF;
    28. t1 ^= 0x00;
    29. UcharBToString(t1, temp);
    30. cout << temp << endl;
    31. t1 = 0xFF;
    32. t1 ^= t2;
    33. UcharBToString(t1, temp);
    34. cout << temp << endl;
    35. t1 = 0xFF;
    36. t2 = 0x0F;
    37. t1 ^= t2;
    38. UcharBToString(t1, temp);
    39. cout << temp << endl;
    40. return 0;
    41. }

    运行结果如下:

    按位与运算符(&)又是取值运算符。示例 int *pInt = &a;

    按位与运算符(&)还用于引用类型声明。示例 int &b = a;

     六 括号

     括号包括大括号、中括号、小括号。

    大括号{}

    大括号(花括号)中一般包含语句块,其中定义的变量有自己的作用域。大括号常用于条件语句块(如if语句,while语句,switch 条件转移、for 循环等)、函数体、公用体体、结构体体及宏函数定义。示例:

    1. //***********************************************************************
    2. ui8 BStringToUchar(ui8 src[],ui8* destData)
    3. {
    4. ui8 len = strlen(src);
    5. ui8 i;
    6. *destData = 0;
    7. for(i = 0; i < len ; i++)
    8. {
    9. *destData <<= 1;
    10. if(src[i]- '0')
    11. *destData += 1;
    12. }
    13. return *destData;
    14. }
    15. //End of BStringToUchar(ui8 src[],ui8* destData)
    16. //***************************************
    17. typedef enum
    18. {
    19. BI_IO = 0, //bidirectional I/O
    20. PP_OUT, //push_pull out
    21. HI_IN, //high impendence in
    22. ODR_OUT //open drain out
    23. }STC32G_IOMODE;
    24. //***************************************
    25. typedef struct
    26. {
    27. STC32G_IOPORT port; //I/O port
    28. ui8 pins; //I/O pins
    29. STC32G_IOMODE mode; // I/O mode
    30. BOOL pullUpEnable; //pull up enable/disable
    31. BOOL pullDownEnable; //Pull down enable/disable
    32. BOOL drvEn; //drive ability enhance enable/disable
    33. BOOL speedHi; // I/O speed high/normal
    34. BOOL dIEnable; // digtal signal input enable/disable
    35. BOOL sTEnable; //schmitt trigger enable/disable
    36. }STC32G_IOTypeDef;

    我们知道在C语言中,变量必须先定义后使用,否则就会编译出错,特别是在Keil C51中更是如此。示例:下面程序编译不会有问题

    1. /*main.c
    2. Designed by Bill Liu
    3. Version 0.0
    4. Modified last by Bill Liu on 11/26/2022
    5. */
    6. #include "main.h"
    7. //#include "config.h"
    8. //#include "STC32G_Timer.h"
    9. #include "STC32G_Delay.h"
    10. //#include "STC32G_comparator.h"
    11. ui8 t1 = 250;
    12. ui16 t2 = 65533;
    13. i32 t3 = -165533;
    14. f32 t4 = 51.25;
    15. f64 t5 = -3.14;
    16. ui8 t6 = 0;
    17. ui16 t7 = 0;
    18. i32 t8 = 0;
    19. f32 t9 = 0;
    20. f64 t10 = 0;
    21. ui8 str[20] = {0};
    22. ui8 str1[20] = "Hello World";
    23. void main()
    24. {
    25. SysInit();
    26. Uart1_Init(VBAUD_8BITS,G1, 0, 9600);
    27. EEPROM_SectorErase(0x00);
    28. EEPROM_Write_nChar(0x00,&t1,1);
    29. EEPROM_Write_Integer(0x01,t2);
    30. EEPROM_Write_Long(0x03,t3);
    31. EEPROM_Write_Float(0x07,t4);
    32. EEPROM_Write_Double(0x0B,t5);
    33. EEPROM_Write_String(0x13,str1);
    34. while(1)
    35. {
    36. EEPROM_Read_nChar(0x00,&t6,1);
    37. LongToString(t6,str);
    38. Uart1_SendString(str);
    39. Uart1_SendString("\r\n");
    40. EEPROM_Read_Integer(0x01,&t7);
    41. LongToString(t7,str);
    42. Uart1_SendString(str);
    43. Uart1_SendString("\r\n");
    44. EEPROM_Read_Long(0x03,&t8);
    45. LongToString(t8,str);
    46. Uart1_SendString(str);
    47. Uart1_SendString("\r\n");
    48. EEPROM_Read_Float(0x07,&t9);
    49. FloatString(t9,str,2);
    50. Uart1_SendString(str);
    51. Uart1_SendString("\r\n");
    52. EEPROM_Read_Double(0x0B,&t10);
    53. FloatString(t10,str,2);
    54. Uart1_SendString(str);
    55. Uart1_SendString("\r\n");
    56. EEPROM_Read_String(0x13,str);
    57. Uart1_SendString(str);
    58. Uart1_SendString("\r\n");
    59. Uart1_SendString("\r\n");
    60. Delayxms(1000);
    61. }
    62. }
    63. //End of main()

    编译结果如下:

     下面在程序中临时定义一个变量(ui16 t11 = t1 * t2;),修改后的程序如下:

    1. /*main.c
    2. Designed by Bill Liu
    3. Version 0.0
    4. Modified last by Bill Liu on 11/26/2022
    5. */
    6. #include "main.h"
    7. //#include "config.h"
    8. //#include "STC32G_Timer.h"
    9. #include "STC32G_Delay.h"
    10. //#include "STC32G_comparator.h"
    11. ui8 t1 = 250;
    12. ui16 t2 = 65533;
    13. i32 t3 = -165533;
    14. f32 t4 = 51.25;
    15. f64 t5 = -3.14;
    16. ui8 t6 = 0;
    17. ui16 t7 = 0;
    18. i32 t8 = 0;
    19. f32 t9 = 0;
    20. f64 t10 = 0;
    21. ui8 str[20] = {0};
    22. ui8 str1[20] = "Hello World";
    23. void main()
    24. {
    25. SysInit();
    26. Uart1_Init(VBAUD_8BITS,G1, 0, 9600);
    27. EEPROM_SectorErase(0x00);
    28. EEPROM_Write_nChar(0x00,&t1,1);
    29. EEPROM_Write_Integer(0x01,t2);
    30. EEPROM_Write_Long(0x03,t3);
    31. EEPROM_Write_Float(0x07,t4);
    32. EEPROM_Write_Double(0x0B,t5);
    33. EEPROM_Write_String(0x13,str1);
    34. while(1)
    35. {
    36. EEPROM_Read_nChar(0x00,&t6,1);
    37. LongToString(t6,str);
    38. Uart1_SendString(str);
    39. Uart1_SendString("\r\n");
    40. EEPROM_Read_Integer(0x01,&t7);
    41. LongToString(t7,str);
    42. Uart1_SendString(str);
    43. Uart1_SendString("\r\n");
    44. EEPROM_Read_Long(0x03,&t8);
    45. LongToString(t8,str);
    46. Uart1_SendString(str);
    47. Uart1_SendString("\r\n");
    48. EEPROM_Read_Float(0x07,&t9);
    49. FloatString(t9,str,2);
    50. Uart1_SendString(str);
    51. Uart1_SendString("\r\n");
    52. EEPROM_Read_Double(0x0B,&t10);
    53. FloatString(t10,str,2);
    54. Uart1_SendString(str);
    55. Uart1_SendString("\r\n");
    56. EEPROM_Read_String(0x13,str);
    57. Uart1_SendString(str);
    58. Uart1_SendString("\r\n");
    59. Uart1_SendString("\r\n");
    60. ui16 t11 = t1 * t2;
    61. Delayxms(1000);
    62. }
    63. }
    64. //End of main()

    编译结果如下:

     编译出错。

    下面将新加代码加上一个大括号,代码如下:

    1. /*main.c
    2. Designed by Bill Liu
    3. Version 0.0
    4. Modified last by Bill Liu on 11/26/2022
    5. */
    6. #include "main.h"
    7. //#include "config.h"
    8. //#include "STC32G_Timer.h"
    9. #include "STC32G_Delay.h"
    10. //#include "STC32G_comparator.h"
    11. ui8 t1 = 250;
    12. ui16 t2 = 65533;
    13. i32 t3 = -165533;
    14. f32 t4 = 51.25;
    15. f64 t5 = -3.14;
    16. ui8 t6 = 0;
    17. ui16 t7 = 0;
    18. i32 t8 = 0;
    19. f32 t9 = 0;
    20. f64 t10 = 0;
    21. ui8 str[20] = {0};
    22. ui8 str1[20] = "Hello World";
    23. void main()
    24. {
    25. SysInit();
    26. Uart1_Init(VBAUD_8BITS,G1, 0, 9600);
    27. EEPROM_SectorErase(0x00);
    28. EEPROM_Write_nChar(0x00,&t1,1);
    29. EEPROM_Write_Integer(0x01,t2);
    30. EEPROM_Write_Long(0x03,t3);
    31. EEPROM_Write_Float(0x07,t4);
    32. EEPROM_Write_Double(0x0B,t5);
    33. EEPROM_Write_String(0x13,str1);
    34. while(1)
    35. {
    36. EEPROM_Read_nChar(0x00,&t6,1);
    37. LongToString(t6,str);
    38. Uart1_SendString(str);
    39. Uart1_SendString("\r\n");
    40. EEPROM_Read_Integer(0x01,&t7);
    41. LongToString(t7,str);
    42. Uart1_SendString(str);
    43. Uart1_SendString("\r\n");
    44. EEPROM_Read_Long(0x03,&t8);
    45. LongToString(t8,str);
    46. Uart1_SendString(str);
    47. Uart1_SendString("\r\n");
    48. EEPROM_Read_Float(0x07,&t9);
    49. FloatString(t9,str,2);
    50. Uart1_SendString(str);
    51. Uart1_SendString("\r\n");
    52. EEPROM_Read_Double(0x0B,&t10);
    53. FloatString(t10,str,2);
    54. Uart1_SendString(str);
    55. Uart1_SendString("\r\n");
    56. EEPROM_Read_String(0x13,str);
    57. Uart1_SendString(str);
    58. Uart1_SendString("\r\n");
    59. Uart1_SendString("\r\n");
    60. {ui16 t11 = t1 * t2;}
    61. Delayxms(1000);
    62. }
    63. }
    64. //End of main()

    编译结果如下:

    编译通过。

    中括号[]

    主要用于数组声明及数组元素的访问。 示例:

    ui8 str[] = "";   str[0] = 'a';

    小括号()

    小括号的用途有几下方面,函数及函数声明,宏函数及宏函数定义,表达式中用于改变运算的优先级,for循环,while及do while循环,switch 条件转移语句等。示例:

    函数及函数声明

    //********************************************************
    void SysInit(); //init System speed  fastest

    函数源文件

    //********************************************************
    void SysInit() //init System speed  fastest
    {
        EAXFR = 1;        //visit XFR enable
        CKCON = 0x00; //set outer data bus speed fastest
        WTST = 0x00;  //CPU wait 0 to run program
    }
    //End of SysInit()

    函数调用:上面示例已有调用函数实例,不再举例。

    改变表达式中的优先级: t1 = (t2 +10)*t3;

    #号的用法 

    #用于包含头文件及宏定义,放在行的开头,以#打头的行末尾不可有分号。示例:

    #include
    #include
    #include

    # define PI 3.14f

    标点符号

    C与C++语言中常用的标点符号包含,逗号(,)、分号(;)、冒号(:)、问号(?)、感叹号(!)、单引号(‘)、双引号(“)、小数点(.)。

    逗号(,)

    逗号在C与C++语言中被用作分隔符,起分隔表达式、参数、元素等作用。

    用在变量声明中 示例: int a,b,c; float: x = 0.10, y = 0.3;

    用在函数列表中做参数分隔 示例void swap(int x, int y);

    用在数组声明中做元素分隔 示例int a[10] ={0,1,2,3,4,5,6,7,8,9};

    数值梯次传递  示例

    1. #include <iostream>
    2. #include <stdio.h>
    3. #include <stdlib.h>
    4. using namespace std;
    5. int t1 = 0xFF;
    6. int t2 = 0xF0;
    7. int t3 = 0;
    8. int t4 =20;
    9. unsigned char temp[20] = "";
    10. char a1[10] = {0,1,2,3,4,5,6,7,8,9};
    11. int main()
    12. {
    13. t1 = (t2,t3,t4);
    14. cout << t1 << endl;
    15. return 0;
    16. }

    运行结果如下:

     从上面的结果可以看出赋予t1的是t4的值。

    分号(;)

    分号(;)在C与C++语言中被用作结束符。如果一行代码只有分号,我们称之为空语句。我们需将它与空操作区分开。空语句不会被编译,或者说编译后不会增加大编译后的可执行文件的大小。空操作_nop_()则会让CPU在一个时钟周期内什么都不做,常被用来延时。

    枚举、结构体、类的花括号外结尾处必须有分号。do while循环的while后面的小括号后需有分号。

    for循环的for后面小括号里的前两个操作结束必须是分号,最后一个操作不能有分号。

    函数体的右花括号后不需要分号。

    冒号(:)

    在C与C++语言中的程序中冒号被放在编号的后面,组成编号。常见于go to语句与switch 语句。

    另外在C++中被用于继承类声明及子类访问父类对象及函数等。还与问号一起用于三目运算中,示例: t1 =  a > b? a: b;

    感叹号(!)

    在C与C++语言中的程序中感叹号为非运算符。

    单引号(‘)

    在C与C++语言中的程序中,单引号须成对使用,用以表示字符,单引号对内有且只能有一个字符。

    双引号(“)

    在C与C++语言中的程序中,双引号须成对使用,用以表示字符串。双引号对中可以有多个字符,也可为空。

    小数点(.)

    在C与C++语言中的程序中, 小数点(.)除用于浮点数外,还用作运算符,用于结构体或类对象访问成员变量(或函数)。示例:

    1. //***************************************************************************************
    2. void STC32G_IOInit(STC32G_IOTypeDef mstruct)
    3. {
    4. switch(mstruct.port)
    5. {
    6. case SCT_P0:
    7. STC32G_P0PinsInit(mstruct.pins, mstruct.mode, mstruct.pullUpEnable, mstruct.pullDownEnable,mstruct.drvEn,mstruct.speedHi,mstruct.dIEnable, mstruct.sTEnable);
    8. break;
    9. case SCT_P1:
    10. STC32G_P1PinsInit(mstruct.pins, mstruct.mode, mstruct.pullUpEnable, mstruct.pullDownEnable,mstruct.drvEn,mstruct.speedHi,mstruct.dIEnable, mstruct.sTEnable);
    11. break;
    12. case SCT_P2:
    13. STC32G_P2PinsInit(mstruct.pins, mstruct.mode, mstruct.pullUpEnable, mstruct.pullDownEnable,mstruct.drvEn,mstruct.speedHi,mstruct.dIEnable, mstruct.sTEnable);
    14. break;
    15. case SCT_P3:
    16. STC32G_P3PinsInit(mstruct.pins, mstruct.mode, mstruct.pullUpEnable, mstruct.pullDownEnable,mstruct.drvEn,mstruct.speedHi,mstruct.dIEnable, mstruct.sTEnable);
    17. break;
    18. case SCT_P4:
    19. STC32G_P4PinsInit(mstruct.pins, mstruct.mode, mstruct.pullUpEnable, mstruct.pullDownEnable,mstruct.drvEn,mstruct.speedHi,mstruct.dIEnable, mstruct.sTEnable);
    20. break;
    21. case SCT_P5:
    22. STC32G_P5PinsInit(mstruct.pins, mstruct.mode, mstruct.pullUpEnable, mstruct.pullDownEnable,mstruct.drvEn,mstruct.speedHi,mstruct.dIEnable, mstruct.sTEnable);
    23. break;
    24. case SCT_P6:
    25. STC32G_P6PinsInit(mstruct.pins, mstruct.mode, mstruct.pullUpEnable, mstruct.pullDownEnable,mstruct.drvEn,mstruct.speedHi,mstruct.dIEnable, mstruct.sTEnable);
    26. break;
    27. case SCT_P7:
    28. STC32G_P7PinsInit(mstruct.pins, mstruct.mode, mstruct.pullUpEnable, mstruct.pullDownEnable,mstruct.drvEn,mstruct.speedHi,mstruct.dIEnable, mstruct.sTEnable);
    29. break;
    30. }
    31. }
    32. //End of STC32G_IOInit(STC32G_IOTypeDef mstruct)

  • 相关阅读:
    Xcode13 “消失”的Info.plist文件
    Hive用户中文使用手册系列(一)
    流量管制-令牌桶与漏桶
    群接龙大团长有哪些,群接龙大团长如何对接?
    聊聊写代码的20个反面教材
    01 邂逅typescript,环境搭建
    Oracle递归查询树形数据
    软件设计模式白话文系列(八)桥接模式
    Android 通话常见错误码汇总
    DGIOT基于低代码amis配置联动短信告警
  • 原文地址:https://blog.csdn.net/billliu66/article/details/128105392