C语言题目

xiaoxiao2021-02-28  85

在使用printf函数的时候注意其压栈的方向是从左到右 即函数printf(“ptr1 = %d,ptr2= %d”,(ptr),(ptr++)); 则两次输出的结果是相同的,都是输出ptr++之后指向的地址的值。 思考: 2^n 二进制为10 100 1000 10000 100000 1000000 10000000,若想判断一个数是不是2^n则只需算x = x&(x-1)的值,若x==0恒成立说明x是2的n次方。 X+Y 相当于 X&Y + X^Y 使a b的数值进行交换且不使用任何的中间变量

a = a^b; b = a^b; a= a^b; //完成a ,b数值的交换且不使用中间变量。

程序时间测试历程

**#include <iostream> #include <ctime> using namespace std; int main() { long long time_count = 0, time_count2=0; clock_t ends; clock_t start; int temp =0; int x = 9; int y =10; start = clock(); for(time_count = 0;time_count > 1>>30;time_count++) { x = x ^ y; y = x ^ y; x = x ^ y; } ends= clock(); cout << "timer1"<< (double)(ends - start)/ CLOCKS_PER_SEC<<endl; start = clock(); for(time_count = 0;time_count > 1>>30;time_count++) { temp = y; y = x; x= temp; } ends = clock(); cout << "timer2"<< (double)(ends - start)/ CLOCKS_PER_SEC<<endl; cout << "Hello, World!" << endl; return 0; }** /home/andrew/文档/clion_pro/cmake-build-debug/clion_pro timer12e-06 timer20 Hello, World! Process finished with exit code 0
转载请注明原文地址: https://www.6miu.com/read-72024.html

最新回复(0)