推介:| 調解員課程 | Makeup Course | Hypnosis course | English course | NLP training | cissp cisa cism | 營養學課程 |

發新話題
打印

開始撰寫C++程式的問題

開始撰寫C++程式的問題

想請問一下interpreter與compiler有何不同, 兩者之間有何優點和缺點, 以及portability是什麼意思??

TOP

引用:
原帖由 花之慶次 於 2007-3-19 00:05 發表
想請問一下interpreter與compiler有何不同, 兩者之間有何優點和缺點, 以及portability是什麼意思??
compiler(假定已和linker結合了)把源代碼編譯為機器碼(machine code)或虛擬機器(virtual machine)的位元碼(byte code), 可以直接在機器運行. 如C/C++, Java.
interpreter則把源代碼實時在機器上執行.  如perl, python.
如不討論虛擬機器, compiler生成的機器碼的運行速度比較interpreter實時執行快.

portability- 指把已開發應用程式, 由一個作業系統平台改成可在另一個平台運行的可能性; 又或指把用某一個編程語言開發的應用程式, 由一個編譯器改成可在另一個編譯器成功編譯的可能性.


相關搜索目錄: 作業系統 語言
IT代工/鎗手一名!
小弟並唔平, 但絕唔係貴!

TOP

Complier will turn your high level code into machine code, which can be runned much faster.

Intepreter will only read your high level codes (eg scripts) line by line and execute the order, which is much slower.

TOP

然則, 又如何定義有關ANSI/ISO C++的標準??

TOP

引用:
原帖由 花之慶次 於 2007-3-19 23:42 發表
然則, 又如何定義有關ANSI/ISO C++的標準??
閣下可以購買以下文本,
自會清楚:
http://webstore.ansi.org/ansidocstore/product.asp?sku=INCITS%2FISO%2FIEC+14882%2D2003&source=google&adgroup=c++&keyword=c%2B%2B%20standards&gclid=CLv8_uSRgosCFRCObgodmnnTKQ
IT代工/鎗手一名!
小弟並唔平, 但絕唔係貴!

TOP

在C++中, 如何去分辨出何謂語法錯誤(syntax error), 何謂語意錯誤(semantic error)??

TOP

Syntax error occurs when you write code in a manner not allowed by the rules of the language. It can be identified by the compiler.

Semantic error occurs when the syntax of your code is correct, but the semantics or meaning are not what you intended. It can only be identified when you run the program (after compilation).

The above definitions apply to not only C++, but also the other programming languages.

TOP

如果我想將n1, n2宣告成整數型態變數, 宣告完成以後, 再將n1設值為6, n2設值為8, 最後將n1, n2的值印出, 而我所撰寫的程式究竟出了什麼問題??
#include<iostream>
#include<cstdlib>
using namespace std;
int main(void)
{
    int n1, n2;
    char ch;
    n1=6;
    n2=8;
    ch='w';
    cout << "n1" << + << "n2" << = << n1+n2= << endl;
    system("pause");
    return 0;
}

最主要的是出了什麼問題!!

TOP

cout << "n1" << + << "n2" << = << n1+n2= << endl;
這一句相信應該是這樣吧:
cout << "n1 + n2 = " << n1+n2 << endl;
IT代工/鎗手一名!
小弟並唔平, 但絕唔係貴!

TOP

以下這程式在實際經驗有何用處以及有沒有必要背熟??
// prog3_2.cpp, 印出各種資料型態的長度
#include<iostream>
#include<cstdlib>
using namespace std;
int main(void)
{
    //定義各種資料型態的變數
    unsigned int i=0;
    unsigned short int j=0;
    char ch=' ';
    float f=0.0f;
    double d=0.0;
   
    //印出各種資料型態的長度
    cout << "sizeof(int)=" << sizeof(int) << endl;
    cout << "sizeof(long int)=" << sizeof(long int) << endl;
    cout << "sizeof(unsigned int)=" << sizeof(i) << endl;
    cout << "sizeof(short int)=" << sizeof(short int) << endl;
    cout << "sizeof(unsigned short int)=" << sizeof(j) << endl;
    cout << "sizeof(char)=" << sizeof(ch) << endl;
    cout << "sizeof(float)=" << sizeof(f) << endl;
    cout << "sizeof(double)=" << sizeof(d) << endl;
    cout << "sizeof(bool)=" << sizeof(bool) << endl;
    system("pause");
    return 0;
}

TOP

這是一個整數資料型態的溢位, 究竟何謂溢位?
// prog3_3.cpp, 整數資料型態的溢位
#include<iostream>
#include<cstdlib>
using namespace std;
int main(void)
{
    int i=2147483647;       // 宣告i為整數, 並設值為2147483647
   
     cout << "i=" << i << endl;  // 印出i 的值
     cout << "i+1=" << i+1 << endl;  // 印出i+1的值
     cout << "i+2=" << i+2 << endl;  // 印出i+2的值
     system("pause");
     return 0;
}

TOP

如果以ASCII碼中, 英語小寫a-z是不是代表不同的數字?? 以h為例, 是不是就是以104來作為代表??
同時, 有關二進位, 十進位的轉換是如何計算的呢??

[ 本帖最後由 花之慶次 於 2007-4-3 23:55 編輯 ]

TOP

引用:
原帖由 jayzhou_2046 於 2007-3-19 11:19 發表

compiler(假定已和linker結合了)把源代碼編譯為機器碼(machine code)或虛擬機器(virtual machine)的位元碼(byte code), 可以直接在機器運行. 如C/C++, Java.
interpreter則把源代碼實時在機器上執行.  如perl, ...
就是这个理~

TOP

有些奇怪

// prog1_1.cpp.cpp : 定義主控台應用程式的進入點。
//

#include "stdafx.h"
#include<iostream>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])

{
        cout << "Hello!!我是陳大文, 你好" << endl;
        system("pause");
        return 0;
}

執行如下:
'prog1_1.cpp.exe': 已載入 'C:\Documents and Settings\Mau hung Li\My Documents\Visual Studio 2005\Projects\prog1_1.cpp\Debug\prog1_1.cpp.exe',已載入符號
'prog1_1.cpp.exe': 已載入 'C:\WINDOWS\system32\ntdll.dll',未載入符號
'prog1_1.cpp.exe': 已載入 'C:\WINDOWS\system32\kernel32.dll',未載入符號
偵錯工具:: 處理序載入期間,發生未處理的非持續性 STATUS_DLL_NOT_FOUND 例外狀況
'[284] prog1_1.cpp.exe: 原生' 程式以返回碼 -1073741515 (0xc0000135) 結束。


為什麼會這樣??

TOP

發新話題


重要聲明:本討論區是以即時上載留言的方式運作,本網站對所有留言的真實性、完整性及立場等,不負任何法律責任。而一切留言之言論只代表留言者個人意見,並非本網站之立場,用戶不應信賴內容,並應自行判斷內容之真實性。於有關情形下,用戶應尋求專業意見(如涉及醫療、法律或投資等問題)。由於本討論區受到「即時上載留言」運作方式所規限,故不能完全監察所有留言,若讀者發現有留言出現問題,請聯絡我們。本討論區有權刪除任何留言及拒絕任何人士上載留言,同時亦有不刪除留言的權利。切勿撰寫粗言穢語、誹謗、渲染色情暴力或人身攻擊的言論,敬請自律。本網站保留一切法律權利。


Copyright 1997- Xocat. All Right Reserved.