題目和結果記錄

計算轉爲二進制之後數字1的數目

int func(int x)
{
    int count=0;
    while (x) {
        count++;
        x=x&(x-1);

    }
    return count;

}

printf壓棧順序和指針,後++

    int arr[]={6,7,8,9,10};
    int *ptr=arr;
   // *(ptr++)+=123;//等於兩句
    *(ptr)+=123;
    ptr++;
    for (int i=0;i<5;i++) {
        printf("%d\n",arr[i]);
    }

    printf("%d\n",*ptr);
    printf("%d,%d\n",*ptr,*(++ptr));


    return 0;

上述代碼結果

c++引用

#include <iostream>
 
using namespace std;
 
int main ()
{
   // 聲明簡單的變量
   int    i;
   double d;
 
   // 聲明引用變量
   int&    r = i;
   double& s = d;
   
   i = 5;
   cout << "Value of i : " << i << endl;
   cout << "Value of i reference : " << r  << endl;
 
   d = 11.7;
   cout << "Value of d : " << d << endl;
   cout << "Value of d reference : " << s  << endl;
   
   return 0;
}
Value of i : 5
Value of i reference : 5
Value of d : 11.7
Value of d reference : 11.7

類型轉換

    float a=1.0f;
    cout<<(int)a<<endl;
    cout<<&a<<endl;
    //cout<<(int)&a<<endl;
    cout<<(int&)a<<endl;
    cout<<boolalpha<<((int)a == (int&)a)<<endl;//將0/1打印成bool或者false

    float b=0.0f;
    cout<<(int)b<<endl;
    cout<<&b<<endl;
    //cout<<(int)&a<<endl;
    cout<<(int&)b<<endl;
    cout<<boolalpha<<((int)b == (int&)b)<<endl;//將0/1打印成bool或者false

在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章