标签:style blog http color io os 使用 ar for
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a = 1, b = 2;
printf("%p,%p\n", &a, &b); //a的地址大于b的地址
char *p1 = malloc(1);
char *p2 = malloc(1);
printf("%p,%p\n", &p1, &p2);//p1的地址大于p2的地址
printf("%p,%p\n", p1, p2);//p1指向的地址小于p2指向的地址
return 0;
}
char *p = "liuwei"; //指针只存了地址
printf("%d,%d\n",sizeof(p),sizeof("liuwei")); // 4 7
#include <stdio.h>
int a;
int a;
int a;
int main()
{
printf("%d\n", a); //结果输出0.
return 0;
}
#include <stdio.h>
int main()
{
gogo();
return 0;
}
#include <stdio.h>
void gogo()
{
printf("gogo\n");
}
#include <stdio.h>
void gogo();//函数声明
int main()
{
gogo();
}
void gogo()
{
printf("gogo\n");
}
#include <stdio.h>
#include <windows.h>
#include <process.h>
void runMsg(void *p)
{
MessageBoxA(0, "hello", "world", 0);
}
void main()
{
_beginthread(runMsg, 0, NULL);
_beginthread(runMsg, 0, NULL);
_beginthread(runMsg, 0, NULL);
getchar();//不加getchar()不行,因为主线程结束了,其他线程都挂掉了
}
#include <stdio.h>
#include <windows.h>
#include <process.h>
void run(void *p)
{
MessageBoxA(0, "hello", p, 0);
}
int main()
{
_beginthread(run, 0, "ABC");
_beginthread(run, 0, "CDE");
_beginthread(run, 0, "XYZ");
getchar();
return 0;
}
#include <stdio.h>
#include <windows.h>
#include <process.h>
struct STU
{
char name[10];
char title[10];
};
struct STU stu[3] = { {"hello","world"}, {"fuck","shit"}, {"apple","pear"} };
void run(void *p)
{
struct STU *tmp = (struct STU *)p;
MessageBoxA(0, tmp->name, tmp->title, 0);
}
int main()
{
for (int i = 0; i < 3;i++)
{
_beginthread(run, 0, &stu[i]);
}
getchar();
return 0;
}
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
typedef struct
{
unsigned char ch1 : 1;
unsigned char ch2 : 1;
unsigned char ch3 : 1;
unsigned char ch4 : 1;
unsigned char ch5 : 1;
unsigned char ch6 : 1;
unsigned char ch7 : 1;
unsigned char ch8 : 1;
}bit;
int main()
{
int num;
scanf("%d", &num);
bit *mybit =
#for (int i = 3; i >= 0; i--) //地址要从高字节打到低字节
{
printf("%d%d%d%d %d%d%d%d ",
mybit[i].ch8, mybit[i].ch7, mybit[i].ch6, mybit[i].ch5,
mybit[i].ch4, mybit[i].ch3, mybit[i].ch2, mybit[i].ch1);
}
return 0;
}
#include <stdio.h>
int find(int *a, int n, int key)
{
int low = 0, high = n - 1;
int mid, count = 0;
while (low <= high)
{
printf("查找第%d次\n", ++count);
//mid = (low + high) / 2; 二分查找bug版本
//mid = low + (high - low) / 2; 二分查找正确版
mid = low + (high - low) * (key - a[low]) / (a[high] - a[low]);//插值查找
if (a[mid] == key)
return mid;
else if (a[mid] < key)
low = mid + 1;
else
high = mid - 1;
}
return -1;
}
int main()
{
int i;
int a[1024 * 100];
for (i = 0; i < 1024 * 100; i++)
a[i] = i;
int pos = find(a, 1024 * 100, 102);
if (pos != -1)
printf("%d %d\n", pos, a[pos]);
else
printf("没有找到\n");
}
#include <stdio.h>
#include <string.h>
#define N 50
struct stack
{
int top;
int data[N];
};
void init_stack(struct stack *p)
{
p->top = -1;
memset(p->data, 0, sizeof(int)*N);
}
int is_empty(struct stack *p)
{
if (p->top == -1)
return 1;
else
return 0;
}
int is_full(struct stack *p)
{
if (p->top == N - 1)
return 1;
else
return 0;
}
void push_stack(struct stack *p, int key)
{
if (is_full(p))
return;
p->top++;
p->data[p->top] = key;
}
int pop_stack(struct stack *p)
{
if (is_empty(p))
return -1;
int data = p->data[p->top];
p->top--;
return data;
}
int main()
{
struct stack mystack;
init_stack(&mystack);
int a[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
int i;
for (i = 0; i < 10; i++)
{
push_stack(&mystack, a[i]);
}
while (!is_empty(&mystack))
{
printf("%d\n", pop_stack(&mystack));
}
return 0;
}
#include <stdio.h>
void bin(int num)
{
if (num == 0)
return;
bin(num / 2);
printf("%d\n", num % 2); // 1 0 1 0
}
int main()
{
bin(10);
return 0;
}
int main()
{
struct stack mystack;
init_stack(&mystack);
int num = 10;
while (num)
{
push_stack(&mystack, num % 2);
num /= 2;
}
while (!is_empty(&mystack))
{
printf("%d\n", pop_stack(&mystack));
}
return 0;
}
9.18 内存区域 全局变量 线程 插值查找 位域 栈的实现
标签:style blog http color io os 使用 ar for
原文地址:http://www.cnblogs.com/l6241425/p/3982219.html