早上参加了***科技的笔试;
题目大概涉及了:
进程和线程的区别;栈和堆分配方式的区别;进程间通信的方式;全局变量和全局静态变量的区别
int (*x)() int *x() int (*x[])()
assert函数的作用;const与宏的区别;栈和堆分配方式的区别;#include"xxoo.h"与#include<xxoo.h>的区别
typedef union {long i; int k[5]; char c;} DATE; struct data { int cat; DATE cow; double dog;} too;
DATE max;
则语句 printf("%d",sizeof(struct date)+sizeof(max));的执行结果是
unsigned char *p1;
unsigned long *p2;
p1=(unsigned char *)0x801000;
p2=(unsigned long *)0x810000;
请问p1+5= ;
p2+5= ;
求过程
后面的代码填空做错了
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <time.h>
- typedef unsigned int u32;
- static void u32_swap(void *a, void *b, int size)
- {
- u32 t = *(u32 *)a;
- *(u32 *)a = *(u32 *)b;
- *(u32 *)b = t;
- }
- static void generic_swap(void *a, void *b, int size)
- {
- char t;
- do {
- t = *(char *)a;
- *(char *)a++ = *(char *)b; *(char *)b++ = t;
- } while (--size > 0);
- }
- void sort(void *base, size_t num, size_t size,
- int (*cmp)(const void *, const void *),
- void (*swap)(void *, void *, int size))
- {
- /* pre-scale counters for performance */
- int i = (num/2) * size, n = num * size, c, r;
- if (!swap)
- swap = (size == 4 ? u32_swap : generic_swap);
- /* heapify */
- for ( ; i >= 0; i -= size) {
- for (r = i; r * 2 < n; r = c) {
- c = r * 2;
- if (c < n - size && cmp(base + c, base + c + size) < 0)
- c += size;
- if (cmp(base + r, base + c) >= 0)
- break;
- swap(base + r, base + c, size);
- }
- }
- /* sort */
- for (i = n - size; i >= 0; i -= size) {
- swap(base, base + i, size);
- for (r = 0; r * 2 < i; r = c) {
- c = r * 2;
- if (c < i - size && cmp(base + c, base + c + size) < 0)
- c += size;
- if (cmp(base + r, base + c) >= 0)
- break;
- swap(base + r, base + c, size);
- }
- }
- }
- int cmpint(const void *a, const void *b)
- {
- return *(int *)a - *(int *)b;
- }
- void printarray(int *array, int size)
- {
- int i;
- printf ("-----------start print array size=%d\n", size);
- for (i = 0; i < size; i++)
- {
- printf ("%d ", array[i]);
- }
- printf ("\n");
- }
- int main()
- {
- int i;
- int *a;
- int size = 10;
- a = (int *) malloc(size * sizeof(int));
- if(a == NULL)
- {
- printf ("malloc\n");
- return 0;
- }
- memset(a, 0, sizeof(int) * size );
- srand(time(NULL));
- for (i = 0; i < size; i++)
- {
- a[i] = rand() % 6599;
- }
- printf ("before sort\n");
- printarray(a, size);
- sort(a, size, sizeof(int), cmpint, NULL);
- printf ("after sort\n");
- printarray(a, size);
- for (i = 0; i < size-1; i++)
- if (a[i] > a[i+1]) {
- printf ("sort() failed!\n");
- printf ("a[%d]=%d > a[%d]=%d\n", i, a[i], i+1, a[i+1]);
- break;
- }
- free(a);
- return 0;
- }