c/c++备忘(持续更新)

  •  宏定义,#,##
    # —— 字符串
    ##——连接两个参数
    #include <iostream>
    using namespace std;

    #define TEST(pid) (cout<<para##pid<<endl);
    #define TEST2(p) (cout<<#p<<endl);
    int main()
    {
        
    int para3 = 3;
        
    int para2 = 2;
        TEST(
    2);    //<==>cout<<para2<<endl;
        TEST(3);    //<==>cout<<para3<<endl;

        TEST2(test)        
    //<==>cout<<"test"<<endl;
        TEST2("test2");    //<==>cout<<""test2""<<endl;
        system("pause");
        
    return 0;
    }


      • const修饰指针
          int a = 10;
          
      int b = 20;
          
      const int* p1 = &a;        //ok
          p1 = &b;                          //ok
          
      //*i = 11;                          //error
          int* const p2 = &a;        //ok
          *p2 = a;                           //ok
          
      //p2 = &b;                        //error

          
      const int* p3;                 //ok
          
      //int* const p4;               //error, must be initialized


      • 声明函数指针数组
      #include <stdlib.h>
      #include 
      <stdio.h>

      //typedef void (*pf) (); 
      void f1(){};
      void f2(){};
      int main()
      {
          
      void (*pf[2]) ()={f1,f2};
          system(
      "pause");
          
      return 0;
      }
      #include <stdlib.h>
      #include 
      <stdio.h>

      typedef 
      void (*pf) (); 
      void f1(){};
      void f2(){};
      int main()
      {
          
      //void (*pf[2]) ()={f1,f2};
          pf p[2]={f1,f2};
          system(
      "pause");
          
      return 0;
      }
      评论
      添加红包

      请填写红包祝福语或标题

      红包个数最小为10个

      红包金额最低5元

      当前余额3.43前往充值 >
      需支付:10.00
      成就一亿技术人!
      领取后你会自动成为博主和红包主的粉丝 规则
      hope_wisdom
      发出的红包
      实付
      使用余额支付
      点击重新获取
      扫码支付
      钱包余额 0

      抵扣说明:

      1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
      2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

      余额充值