Time of Update: 2018-12-05
http://dev.yesky.com/424/2110924.shtml 引言 C/C++語言有一個不同於其它語言的特性,即其支援可變參數,典型的函數如printf、scanf等可以接受數量不定的參數。如:printf ( "I love you" ); printf ( "%d", a );printf ( "%d,%d", a, b ); 第一、二、三個printf分別接受1、2、3個參數,讓我們看看printf函數的原型:int printf ( const char
Time of Update: 2018-12-05
cast是用於類型轉換的,C++中常用的cast有以下幾種:1.static_cast:用於繼承中,子類和父類之間的轉換,用作將子類轉換為父類舉例:Child*ch = new Child();Father* fa =
Time of Update: 2018-12-05
#include <iostream>using namespace std;void fun_1(int n){if(n<2){cout<<n;}if(n>=2){fun_1(n/2);cout<<n%2;}}void fun_3(int n){switch(n){case 10: cout<<"A";break;case 11: cout<<"B";break;case 12:
Time of Update: 2018-12-05
C++中char*\wchar_t*\string\wstring之間的相互轉換:#ifndef USE_H_ #define USE_H_ #include <iostream> #include <windows.h> #include <string> using namespace std; class CUser { public: CUser(); virtual~ CUser();
Time of Update: 2018-12-05
【我解C語言面試題系列】005 按位反轉字元問題按位反轉字元問題 Write a C function to swap the bits of a unsigned char so that its bits become the mirror image of the char. MSBs become its LSBs, e.g. 01111000 binary should become 00011110 binary. 方法一:(最最容易想到的辦法)unsigned char
Time of Update: 2018-12-05
【我解C語言面試題系列】010 從相應位置開始刪除指定字串的相應個字元從相應位置開始刪除指定字串的相應個字元 假設一個字串 " abcdefg ",那麼請你寫一個函數,該函數將會從指定位置開始,刪除指定長度的字元。如:要從第二個開始,刪除2兩個字元。則刪除後的字串是 “adefg”。char *DeleteTheCharacters(char *str,int pos,int len){ char *p = str+pos-1; int tt = strlen(str);
Time of Update: 2018-12-05
【我解C語言面試題系列】006 按位反轉整數問題按位反轉整數問題 Write a C function to swap the bits of a unsigned int so that its bits become the mirror image of the char. MSBs become its LSBs, e.g. 0111100011110111 binary should become 1110111100011110 binary.方法一:(最最容易想到的辦法)
Time of Update: 2018-12-05
【C語言庫函數原始碼】【本程式在Dev C++ 4.9.9.2 下編譯通過】double my_exp(double x){ register double ret, value; __asm__( "fldl2e;" "fmul %%st(1);" "fst %%st(1);/n/t" "frndint;" "fxch;/n/t" "fsub %%st(1);" "f2xm1"
Time of Update: 2018-12-05
【C語言庫函數原始碼】【本程式在Dev C++ 4.9.9.2 下編譯通過】#include <stdlib.h>/* 這個函數調用的是庫函數中的 strtol()函數,關於這個函數的 原始碼後面將會給出。*/int my_atoi(char *str){ return (int) strtol(str, NULL, 10);}/* 下面的兩個函數沒有調用strtol()函數, 而是直接給出了該函數的實現。*/int my_atoi01(const char
Time of Update: 2018-12-05
【我解C語言面試題系列】011 刪除指定字串的相應字元刪除指定字串的相應字元 假設字串 "cabcdefcgchci" ,那麼要求你寫一個函數,把該字串中所有的字元 ’c’ 刪除掉。那麼結果應該是 "abdefghi"。 00和01是用for迴圈來實現的演算法char * DeleteChararcter_00(char *str,int c){ char *p,*ret; for(ret= p = str;*p;p++) { if(*p == c)
Time of Update: 2018-12-05
【我解C語言面試題系列】007 運算子優先順序問題運算子優先順序問題給出下面程式的運行結果:int main(){ if( 0 & 1 == 0) printf("0 & 1 == 0/n"); else printf("0 & 1 != 0/n"); if( 0 & 1 != 0) printf("0 & 1 != 0/n"); else printf("0 & 1
Time of Update: 2018-12-05
【我解C語言面試題系列】002 局部變數和全域變數小結?局部變數和全域變數小結 局部變數
Time of Update: 2018-12-05
【C語言庫函數原始碼】【本程式在Dev C++ 4.9.9.2 下編譯通過】double my_pow(double x, double y){ register double ret, value; double r = 1.0; long p = (long) y; if (x == 0.0 && y > 0.0) return 0.0; if (y == (double) p) { if (p == 0)
Time of Update: 2018-12-05
【C語言庫函數原始碼】【本程式在Dev C++ 4.9.9.2 下編譯通過】double my_ceil(double x){ register double ret; unsigned short int temp1, temp2; __asm__("fnstcw %0" : "=m" (temp1)); temp2 = (temp1 & 0xf3ff) | 0x0800; /* rounding up */ __asm__("fldcw %0" : :
Time of Update: 2018-12-05
【我解C語言面試題系列】003 死迴圈格式問題小結?死迴圈格式問題小結下面是幾個"著名"的死迴圈:(1)作業系統死迴圈;(2)WIN32程式死迴圈;(3)嵌入式系統軟體死迴圈;(4)多線程程式的線程處理函數死迴圈。 而有的時候我們在程式中也要使用死迴圈,只有當條件滿足的時候,才可以break 退出死迴圈,繼續下面的代碼的執行。死迴圈的方案有兩個:while (1){ ……}for ( ; ; ){
Time of Update: 2018-12-05
【C語言庫函數原始碼】【本程式在Dev C++ 4.9.9.2 下編譯通過】double my_pow10(double x){ register double ret, value; __asm__( "fldl2t;/n/t" "fmul %%st(1);/n/t" "fst %%st(1);/n/t" "frndint;/n/t" "fxch;/n/t" "fsub %%st(1);/n/t"
Time of Update: 2018-12-05
【C語言庫函數原始碼】【本程式在Dev C++ 4.9.9.2 下編譯通過】double my_floor(double x){ register double ret; unsigned short int temp1, temp2; __asm__("fnstcw %0" : "=m" (temp1)); temp2 = (temp1 & 0xf3ff) | 0x0400; /* rounding down */ __asm__ ("fldcw %0" : :
Time of Update: 2018-12-05
【C語言庫函數原始碼】【本程式在Dev C++ 4.9.9.2 下編譯通過】/* 對兩個整數相除,傳回型別為div_t, 在stdlib.h標頭檔中定義。 typedef struct { int quot; int rem; } div_t; quot儲存的是商(quotient)。 rem 儲存的是餘數(remainder)。 演算法和ldiv()函數非常類似。 這個函數並不進行分母(除數)為0的檢測。*/ typedef
Time of Update: 2018-12-05
【我解C語言面試題系列】013 以單詞為單位的翻轉字串以單詞為單位的翻轉字串原題:Write a function string reverse string word By word (String input) that reverses a string word by word.For instance: "The house is blue" --> "blue is house The""Zed is dead" -->"dead is Zed"
Time of Update: 2018-12-05
【我解C語言面試題系列】008 去除數組中重複數字問題去除數組中重複數字問題 有一個大小為100的數組,裡面的數字均介於1到99之間,但是裡面的數字有重複,請寫個函數去除數組中的重複數字。 #define INIT_NUM -1方法一:(最最容易想到的辦法)void RemoveBufferRepNum_00(int buffer[]){ int i,j; for(i=0;i<BUFFERSIZE;i++) { for(j =