}*p;
p=0x1000000;
p+0x200=____;
(Ulong)p+0x200=____;
(char*)p+0x200=____;
希望各位达人给出答案和原因,谢谢拉
解答:假设在32位CPU上,
sizeof(long) = 4 bytes
sizeof(char *) = 4 bytes
sizeof(short int) = sizeof(short) = 2 bytes
sizeof(char) = 1 bytes由于是4字节对齐,
sizeof(struct BBB) = sizeof(*p)
= 4 + 4 + 2 + 1 + 1/*补齐*/ + 2*5 + 2/*补齐*/ = 24 bytes (经Dev-C++验证)p=0x1000000;
p+0x200=____;
= 0x1000000 + 0x200*24(Ulong)p+0x200=____;
= 0x1000000 + 0x200(char*)p+0x200=____;
= 0x1000000 + 0x200*4你可以参考一下指针运算的细节
写一段程序,找出数组中第k大小的数,输出数所在的位置。例如{2,4,3,4,7}中,第一大的数是7,位置在4。第二大、第三大的数都是4,位置在1、3随便输出哪一个均可。函数接口为:int find_orderk(const int* narry,const int n,const int k)
要求算法复杂度不能是O(n^2)
谢谢!
可以先用快速排序进行排序,其中用另外一个进行地址查找
代码如下,在VC++6.0运行通过。给分吧^-^//快速排序#include<iostream>usingnamespacestd;intPartition (int*L,intlow,int high)
{
inttemp = L[low];
intpt = L[low];while (low < high)
{
while (low < high && L[high] >= pt)
--high;
L[low] = L[high];
while (low < high && L[low] <= pt)
++low;
L[low] = temp;
}
L[low] = temp;returnlow;
}voidQSort (int*L,intlow,int high)
{
if (low < high)
{
intpl = Partition (L,low,high);QSort (L,low,pl - 1);
QSort (L,pl + 1,high);
}
}intmain ()
{
intnarry[100],addr[100];
intsum = 1,t;cout << "Input number:" << endl;
cin >> t;while (t != -1)
{
narry[sum] = t;
addr[sum - 1] = t;
sum++;cin >> t;
}sum -= 1;
QSort (narry,1,sum);for (int i = 1; i <= sum;i++)
cout << narry[i] << '/t';
cout << endl;intk;
cout << "Please input place you want:" << endl;
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-36439-23.html
但国家面子更重要
当然凭他的数学水平也确实管不了