#include<stdio.h>
int ave(int a, int b)
{
return (a & b) + ((a ^ b) >> 1);
}
int main()
{
int a = 10;
int b = 14;
printf("%d", ave(a,b));
}
//
巧妙使用運算符會使程序簡單
本文出自 “痕跡” 博客,請務必保留此出處http://wpfbcr.blog.51cto.com/10696766/1703662
#include<stdio.h>
int ave(int a, int b)
{
return (a & b) + ((a ^ b) >> 1);
}
int main()
{
int a = 10;
int b = 14;
printf("%d", ave(a,b));
}
//
巧妙使用運算符會使程序簡單
本文出自 “痕跡” 博客,請務必保留此出處http://wpfbcr.blog.51cto.com/10696766/1703662
對於C/C++語言來講, const就是隻讀的意思,只在聲明中使用; static一般有2個作用,規定作用域和存儲方式.對於局部變量,static規
C++ explicit構造函數 explicit按字面意思是明確的,顯式的。在C++類中只要定義的構造函數編譯器就不會幫你生成默認構造函數。
爲什麼使用const?採用符號常量寫出的代碼更容易維護;指針常常是邊讀邊移動,而不是邊寫邊移動;許多函數參數是隻讀不寫的。c
//螺旋隊列.cpp// 21 22 ... ...// 20 7 8 9 10// 19 6 1 2 11// 18 5 4 3 12// 17 16 15 14 13//看