zxj3791

导航

2022年4月17日

C++ || 求一个数中1的位数

摘要: 点击查看代码 #include<iostream> using namespace std; int f(int x) { int count = 0; while(x) { if (x % 10 == 1) { ++count; } x /= 10; } return count; } int m 阅读全文

posted @ 2022-04-17 16:03 有序 阅读(70) 评论(0) 推荐(0) 编辑

2022年4月16日

C++ || const_cast 将const变量转为非const

摘要: 点击查看代码 #include <iostream> using namespace std; int main() { int a =5; const int* p=&a;//需要用&a,对应左边的 指针变量 cout<<"a的值:"<<a<<endl; cout<<"a的地址:"<<&a<<en 阅读全文

posted @ 2022-04-16 17:22 有序 阅读(181) 评论(0) 推荐(0) 编辑

C++ || 用类 写交换函数 ||函数指针传递

摘要: 点击查看代码 #include <iostream> using namespace std; void swap(int* a,int* b) //函数参数为指针形式 { int p = *a; *a = *b; *b = p; } int main() { int a = 5; int b = 阅读全文

posted @ 2022-04-16 12:56 有序 阅读(41) 评论(0) 推荐(0) 编辑