筆試

1. 利用宏定義一個8bit的4 5 6 位

#define ClearBitFun(x) ( x &= (~((0x1 << 3) | (0x1 << 4) | (0x1 << 5))))

當時差點沒讀懂題  英文 傷不起

2.忘了

3.考察指針

void Sub_1(char* str)
{
  str =(char*) malloc(100);
}

 

指針做參數 衹能修改指針指向的值  不能修改指針的指向

我當時居然瞎bb到了DEP

兩種修改方法

void Sub_1(char** str)
{
    *str =(char*) malloc(100);
}

void Sub_2(char* str)
{
    *(char**)str = (char*)malloc(100);
}
 
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{

    int a = 255;
    
    ClearBitFun(a);
    printf("%d\r\n", a);
    char* str = NULL;
    
    Sub_1(&str);
    strcpy(str,"haha");
    printf(str);

    char* str1 = NULL;
    Sub_2((char*)&str1);
    strcpy(str1,"haha");
    printf(str1);
    return 0;
     
}
4 基本的字節考察 

字 word
字節 byte
位 bit

1 word = 2 byte

1 byte = 8 bit

 

/*
从-128到127,共512个数。若无符号,则是0到511 带符号数过程: 1字节8个位,16进制为0x00到0xFF(0x表示16进制),
最高位为符号位,0是正数,1是负数。 因此,0x0就是0,0x1到0x7f为正数1到127,
而0x80到0xff为负数-128到-1 特别注意0x80=-128,0xff=-1,换算方法是按位取反加一
*/

 

5.沒看懂 提議

 

6.你認爲C代碼怎麽設計才能被認爲Good

自由發揮  瞎bb

 

軟件方面

名詞解釋  

mmu
tlb
cache
pagetable

 

編程 一個64為的指針的申請和釋放  這個比較簡單

// Demo.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include "Demo.h"
#include <stdlib.h>  
#include <stdio.h>  
#include <string.h>  
#include <Windows.h>
 
#include <windows.h>  
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <Winbase.h>
#include <time.h>  
#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// 唯一的应用程序对象

CWinApp theApp;
 
using namespace std;
 
#define BIT3 (0x1 << 3)
static int a;

void set_bit3(void) 
{
    a |= BIT3;
}
void clear_bit3(void) 
{
    a &= ~BIT3;
}



#define ClearBitFun(x) ( x &= (~((0x1 << 3) | (0x1 << 4) | (0x1 << 5))))



void Sub_1(char** str)
{
    *str =(char*) malloc(100);
}

void Sub_2(char* str)
{
    *(char**)str = (char*)malloc(100);
}


//Sub_1 里分配的内存没传回来的.
//指针做参数只能修改指针指向的值, 不能修改指针的指向.
//要修改指针本身的值, 用 Sub_1(char** str) 或 Sub_1(char*& str)
 
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{

    int a = 255;
    
    ClearBitFun(a);
    printf("%d\r\n", a);
    char* str = NULL;
    
    Sub_1(&str);
    strcpy(str,"haha");
    printf(str);

    char* str1 = NULL;
    Sub_2((char*)&str1);
    strcpy(str1,"haha");
    printf(str1);
    return 0;
     
}

/*
字  word
字节 byte
位   bit

1 word = 2 byte

1 byte = 8 bit*/
/*
从-128到127,共512个数。若无符号,则是0到511 带符号数过程: 1字节8个位,16进制为0x00到0xFF(0x表示16进制),
最高位为符号位,0是正数,1是负数。 因此,0x0就是0,0x1到0x7f为正数1到127,
而0x80到0xff为负数-128到-1 特别注意0x80=-128,0xff=-1,换算方法是按位取反加一
*/

 

  

 

 

 

  

 

posted on 2016-10-19 11:33  yifi  阅读(169)  评论(0编辑  收藏  举报

导航