不確定自己觀念有沒有錯誤
1.
int a = 3; ===> 有個暫存空間裡面存著3
int c = a + b; ===> 有個暫存空間裡面存著a + b的計算結果
int c = (int) 3.2; ===> 有個暫存空間會儲存3.2轉型的結果(即整數3),這個暫存空間的型態是int
2.
不管是哪種型態,在記憶體裡面都是二進位
不同型態的差別在於"語言處理該資料的方式"不同
例如int型態的變數就會以C"處理int型態的方式"處理,也就是會以"int的方式來儲存該變數、讀取該變數"
3.
同型態變數的賦值其實單純只是把記憶體資料一字不漏得複製過去而已
例如:
int a = 3, b;
b = a; ===> 單純把a這個記憶體位置上的二進位資料完整複製過去b
例如:
int baseAddr = 0x00;
void *ptr = (void *)baseAddr; // 讓ptr指向0x00000000;這個位置
因為(void *)baseAddr會產生一個暫存空間,裡面的值是0x00,而且這個暫存空間的型態是void *
既然暫存空間的型態和ptr的型態同樣都是void *,所以賦值的動作其實只是把暫存空間的二進位資料完整複製過去ptr而已
2012年12月27日 星期四
2012年11月21日 星期三
2012年9月19日 星期三
整數和指標的轉換
http://msdn.microsoft.com/en-us/library/k26sa92e.aspx
整數轉指標:
int baseAddr = 0x00000000;
void *ptr = (void *)baseAddr; // 讓ptr指向0x00000000;這個位置
指標轉整數:
int i = 3;
int *ptr = &i;
int i_Address = (int)ptr; // 將ptr變數儲存的位址轉換成整數
整數轉指標:
int baseAddr = 0x00000000;
void *ptr = (void *)baseAddr; // 讓ptr指向0x00000000;這個位置
指標轉整數:
int i = 3;
int *ptr = &i;
int i_Address = (int)ptr; // 將ptr變數儲存的位址轉換成整數
2012年5月7日 星期一
滑鼠連點
玩龍族大概是用250毫秒
#include <windows.h>
#include <stdio.h>
int main(void)
{
int interval;
printf("Press HOME to start and END to end.\n");
printf("Enter the clicking interval in milliseconds:\n");
scanf("%d", &interval);
while (1) {
if (GetAsyncKeyState(VK_HOME)) {
while (1) {
if (GetAsyncKeyState(VK_END))
break;
mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
Sleep(interval);
}
}
Sleep(10);
}
return 0;
}
#include <windows.h>
#include <stdio.h>
int main(void)
{
int interval;
printf("Press HOME to start and END to end.\n");
printf("Enter the clicking interval in milliseconds:\n");
scanf("%d", &interval);
while (1) {
if (GetAsyncKeyState(VK_HOME)) {
while (1) {
if (GetAsyncKeyState(VK_END))
break;
mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
Sleep(interval);
}
}
Sleep(10);
}
return 0;
}
2012年4月26日 星期四
2012年4月24日 星期二
2012年4月22日 星期日
鏈結串列
http://codepad.org/agZ3XDUC
不管什麼操作都是要先判斷串列是不是為空的
也就是大致上都是長這樣子
if (head == NULL) {
....
}
else {
// 非空時的處理
}
插入的寫法:
while (ptr->next != NULL) {
ptr = ptr->next;
}
ptr->next = malloc(...);
走訪的寫法:
while (ptr != NULL) {
// print node
ptr = ptr->next
}
刪除整條串列:
while (ptr != NULL) {
nextStudent = ptr->next;
delete ptr;
ptr = nextStudent;
}
不管什麼操作都是要先判斷串列是不是為空的
也就是大致上都是長這樣子
if (head == NULL) {
....
}
else {
// 非空時的處理
}
插入的寫法:
while (ptr->next != NULL) {
ptr = ptr->next;
}
ptr->next = malloc(...);
走訪的寫法:
while (ptr != NULL) {
// print node
ptr = ptr->next
}
刪除整條串列:
while (ptr != NULL) {
nextStudent = ptr->next;
delete ptr;
ptr = nextStudent;
}
2012年4月13日 星期五
2012年3月13日 星期二
動態、靜態連結的知識
http://blog.csdn.net/clever101/article/details/5176254
static link:
1. .lib檔: 是.o的打包,也就是這個檔案的內容就是可執行碼
dynamic link:
1. .lib檔: 包含匯入表,幫助連結器知道如何新增匯入表
2. dll檔: 可執行碼
static link:
1. .lib檔: 是.o的打包,也就是這個檔案的內容就是可執行碼
dynamic link:
1. .lib檔: 包含匯入表,幫助連結器知道如何新增匯入表
2. dll檔: 可執行碼
2012年2月21日 星期二
2012年1月1日 星期日
union讓一個變數具有多種形態
enum讓文字來代替數字
bit field可以讓你決定要用幾個bit來存資料,以unsigned int為單位
sequential access -> tape
random access -> harddisk
Macro
#define swap(x, y)是一個Macro
Macro是先代替再把參數代入
/* code */和以下兩者等價:
#if 0
code
#endif
#ifdef DEBUG
code
#endif
#define HELLO( x ) printf( “Hello, ” #x “\n” );
經過HELLO(JOHN)以後會變成printf( “Hello, ” “John” “\n” );
printf會把這些以空格隔開的字串連接起來
#define TOKENCONCAT( x, y ) x ## y
would cause
TOKENCONCAT( O, K )
to become
OK
當傳入的敘述為false時,assert()會呼叫abort()來終止程式,如果有#def NDEBUG,All subsequent assert statements ignored
abort()和exit()的差別
exit會把某些變數和檔案釋放掉,並且呼叫atexit();
但abort不會做上面這些事情
不過程式結束以後作業系統還是會幫你釋放掉就是了
enum讓文字來代替數字
bit field可以讓你決定要用幾個bit來存資料,以unsigned int為單位
sequential access -> tape
random access -> harddisk
Macro
#define swap(x, y)是一個Macro
Macro是先代替再把參數代入
/* code */和以下兩者等價:
#if 0
code
#endif
#ifdef DEBUG
code
#endif
#define HELLO( x ) printf( “Hello, ” #x “\n” );
經過HELLO(JOHN)以後會變成printf( “Hello, ” “John” “\n” );
printf會把這些以空格隔開的字串連接起來
#define TOKENCONCAT( x, y ) x ## y
would cause
TOKENCONCAT( O, K )
to become
OK
當傳入的敘述為false時,assert()會呼叫abort()來終止程式,如果有#def NDEBUG,All subsequent assert statements ignored
abort()和exit()的差別
exit會把某些變數和檔案釋放掉,並且呼叫atexit();
但abort不會做上面這些事情
不過程式結束以後作業系統還是會幫你釋放掉就是了
訂閱:
意見 (Atom)