c语言void nzp,C语言语法学习记录

66b52468c121889b900d4956032f1009.png

8种机械键盘轴体对比

本人程序员,要买一个写代码的键盘,请问红轴和茶轴怎么选?

目录

启用断言测试宏

//#undef _EXAM_ASSERT_TEST_ //禁用

#define _EXAM_ASSERT_TEST_ //启用

#ifdef _EXAM_ASSERT_TEST_ //启用断言测试

void assert_report(const char * file_name, const char * function_name, unsigned int line_no)

{

printf("n[EXAM]Error Report file_name: %s, function_name: %s, line %un",

file_name, function_name, line_no);

abort();

}

#define ASSERT_REPORT( condition )

do{

if ( condition )

NULL;

else

assert_report( __FILE__, __func__, __LINE__ );

}while(0)

#else // 禁用断言测试

#define ASSERT_REPORT( condition ) NULL

#endif /* end of ASSERT */

插入法排序

#include

#include

#define N 100

void main()

{

int arr[N], nj, ni, i, h;

for (i = 0; i < N; i++)

{

arr[i] = rand();

}

for (i = 1; i < N; i++)

{

h = arr[i];.

for (ni = i - 1; ni >= 0; ni--)

{

if (h < arr[ni])

{

arr[ni + 1] = arr[ni];

arr[ni] = h;

}

}

}

for (i = 0; i < N; i++)

{

printf("%dt", arr[i]);

}

system("pause");

}

函数并不能改变实参的值下面的例子将证明,即使用swap函数对a,b做了交换,也是没有效果的。

#include

void swap(int a, int b);

void main()

{

int a, b;

a = 1;

b = 2;

swap(a, b);

printf("%d,%dt", a, b);

system("pause");

}

void swap(int a, int b)

{

int temp;

temp = a;

a = b;

b = temp;

}但是用指针来作为传递就会有效。我们对上面的例子稍作更改,如下:

#include

void swap(int a, int b);

void main()

{

int a, b;

a = 1;

b = 2;

swap(&a, &b);

printf("%d,%dt", a, b);

system("pause");

}

void swap(int *a, int *b)

{

int temp;

temp = *a;

*a = *b;

*b = temp;

}

数组的函数传递均为引用传递,即将数组的首地址传给函数的形参。所以形参的数组如何定义都可。如:void nzp(int a[])或者void nzp(int a[10])。都是没问题的。

并归排序这里只给出函数,如需测试请在主函数中调用mergesort()函数。

#include /*含ma l l o c ( ) 的头文件*/

#include

void merge(int *arr, int p, int q, int r) {//定义arr指向数组首地址(这里定义为arr[]或arr[“随意数字”]也可以),p为数组首位,q为中间位,r为末位

int n1, n2, i, j, k, *arrl, *arrr;

n1 = q - p + 1;//定义n1为p到q的元素个数

n2 = r - q;//定义n2为q+1到r的元素个数

arrl = (int*)calloc(n1, sizeof(int));//为arrl动态分配n1个int内存

arrr = (int*)calloc(n2, sizeof(int));//未arrr动态分配内存

if (arrl == NULL || arrr == NULL)//判断内存是否分配成功,如果不成功则关闭程序

{

abort();

}

for (i = 0; i < n1; i++)//将arr数组的前p到q个赋给arrl

{

arrl[i] = arr[p + i];

}

for (i = 0; i < n2; i++)//将arr数组的q+1到r个赋给arrr

{

arrr[i] = arr[q + 1 + i];

}

i = j = 0;//i,j重新归零,指向数组的首个位置

for (k = p; k <= r; k++)//数组合并并排序

{

if ((arrl[i]= n2)//i= n2是防止arrr越界。越界的值很有可能为0,造成条件一直成立。

{

arr[k] = arrl[i++];//将小的值放到arr数组中并且i加1

}

else

{

arr[k] = arrr[j++];

}

}

free(arrl);//释放arrl动态内存

free(arrr);//释放arrr动态内存

arrl = arrr = NULL;//将指针归零,此步骤不可省去,否则会产生野指针

}

void mergesort(int *arr, int p, int r) {

if (p < r)

{

int q;

q = (r + p) / 2;

mergesort(arr, p, q);

mergesort(arr, q + 1, r);

merge(arr, p, q, r);

}

}

private void switchPilotMode(@PilotConstants.PilotMode int mode) { Dog.d(TAG, "switchPilotMode: mode=" + mode + ", mPilotMode: " + mPilotMode); startNZPCheck(mode); boolean preIsNzpStatus = PilotModeHelper.isNzpStatus(mPilotMode); boolean preIsNzpPlusStatus = PilotModeHelper.isNzpPlusStatus(mPilotMode); Dog.d(TAG, "switchPilotMode: preIsNzpStatus=" + preIsNzpStatus); Dog.d(TAG, "switchPilotMode: preIsNzpPlusStatus=" + preIsNzpPlusStatus); mPilotMode = mode; boolean currentIsNzpStatus = PilotModeHelper.isNzpStatus(mPilotMode); boolean currentIsNzpPlusStatus = PilotModeHelper.isNzpPlusStatus(mPilotMode); Dog.d(TAG, "switchPilotMode: currentIsNzpStatus=" + currentIsNzpStatus); Dog.d(TAG, "switchPilotMode: currentIsNzpPlusStatus=" + currentIsNzpPlusStatus); if (currentIsNzpStatus && preIsNzpPlusStatus) { PilotStatusCallbackImpl.get().notifyPilotStatus(PilotConstants.PilotStatus.NZP_RUNNING); } else if (currentIsNzpPlusStatus && preIsNzpStatus) { PilotStatusCallbackImpl.get().notifyPilotStatus(PilotConstants.PilotStatus.NZP_RUNNING_PLUS); } } public void startNZPCheck(int pilotMode) { boolean isNzpRunning = PilotModeHelper.isNzpRunning(pilotMode); Dog.d(TAG, "switchPilotMode isNzpRunning:" + isNzpRunning + ", isNZPBackground: " + isNZPBackground); if (isNzpRunning && isNZPBackground) { setNZPBackground(false); Dog.d(TAG, "switchPilotMode NZP_STARTING, isNZPBackground: " + isNZPBackground); notifyPilotStatus(PilotConstants.PilotStatus.NZP_STARTING); mHandler.postDelayed(mDelayNotifyPilotStatusRunnable, 2000); mHandler.postDelayed(new Runnable() { @Override public void run() { Dog.d(TAG, "switchPilotMode NZP_STARTING, notifyDismissStatus"); PilotMessage dismissMessage = PilotMessageHandler.getInstance().getTopPriorityPilotMessage(PilotMessage.getDismissMessage()); PilotStatusCallbackImpl.get().notifyWidgetStatus(dismissMessage.msgType, dismissMessage.level); } }, 6000); } }
07-14
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值