Download presentation
1
Introduction to Programming
授課老師:林川傑
2
課程資訊 教師 課程網頁 助教 (TA) 林川傑 INS609 分機6610 cjlin@ntou.edu.tw
助教 (TA) 陳邵亨 INS605 分機6636 劉耆定 INS605 分機6636 黃若萍 INS114A 分機6633
3
課程資訊 課本 (Textbook) 評分原則 (Grades)
C Programming - A Modern Approach, K. N. King, 2nd Ed., Norton. 評分原則 (Grades) 期中考 Midterm Exam 30% 期末考 Final Exam 35% 作業及隨堂考 Homework, etc. 30% 平時表現 Additional 5% 期中、期末、作業任一項0分者無法及格
4
Introducing C Chapter 1
5
Programming Languages (程式語言)
Hundreds of languages have been invented. Three major types Machine languages (機械語言、機器碼) Assembly languages (組合語言) High-level languages (高階語言)
6
Machine Languages (機械語言)
Machine-dependent (隨機器而不同) Different machines codes for different kinds of computers IBM x86 machines Sun Sparc Workstation Examples:
7
Assembly Languages (組合語言)
用類似英文的字來代表電腦動作 用 assemblers (組譯器) 來翻譯成機器碼 Example: LOAD PRICE ADD TIP STORE TOTAL assembler
8
High-Level Languages (高階語言)
程式碼就像日常英文 採用數學符號 用 compilers (編譯器) 來編譯成機器碼 Example: TOTAL = PRICE + TIP
9
History of C Origins Ken Thompson at Bell Lab designed a language called B for the further development of UNIX, which was originally written in assembly language. Dennis Ritchie joined the UNIX project and found that B was not well-suited to another platform. So he extended B into C in 1971.
10
History of C Standardization
The first book on C, the C Programming Language, was written by Brian Kernighan and Dennis Ritchie in 1978. By the 1980s, Many slight variations of C existed and they were not always compatible. The American National Standards Institute (ANSI) created a "unambiguous, machine-independent" definition in 1988 and formally approved in 1989 (C89 or C90, or ANSI C).
11
History of C Standardization
It was approved by the International Organization for Standardization (ISO) as international standard ISO/IEC 9899:1990. Some significant changes were added into C. Therefore, it came a new standard ISO/IEC 9899:1999 in (C99) C99 is not universal yet.
12
C-Based Languages C++ includes all the features of C, but adds classes and other features to support object-oriented programming. Java is based on C++. C# is derived from Java and C++. Perl was originally a fairly simple scripting language but now adopted many of the features of C.
13
Philosophy of C C is a low-level language. C is a small language.
C provides access to machine-level concepts. C is a small language. C only provides a limited set of features. C is a permissive language. C allows you a wider degree of programming.
14
Strengths of C Efficiency Portability Power
C programs can run quickly in limited amounts of memory. Portability By developing C compilers in different platforms, C programs can be ported to another machine. Power C's large collection of data types and operators make it powerful.
15
Strengths of C Flexibility Standard library Integration with UNIX
C is now used for applications of all kinds. Moreover, C provides very few restrictions on the use of its features. Standard library C's standard library contains hundreds of useful functions. Integration with UNIX C is powerful in combination with UNIX.
16
Weaknesses of C C programs can be error-prone.
C's flexibility makes it error-prone. Many errors cannot be detected by a C compiler but caught until the program is run. C programs can be difficult to understand. C programmers are often very clever to use and combine the features in many different ways which make the programs hard to understand. C programs can be difficult to modify. C programs can be hard to change if they haven't be carefully designed.
17
Example of Obfuscated C Code
v,i,j,k,l,s,a[99]; main() { for(scanf("%d",&s);*a-s;v=a[j*=v]-a[i], k=i<s,j+=(v=j<s&&(!k&&!!printf(2+"\n\n%c"-(!l<<!j),"#Q"[l^v?(l^j)&1:2])&& ++l||a[i]<s&&v&&v-i+j&&v+i-j))&&!(l%=s), v||(i==j?a[i+=k]=0:++a[i])>=s*k&&++a[--i]) ; } Solutions to the Eight Queens problem, written by Osovslanski and Nissenbaum
18
Suggestions to Effective Use of C
Learn how to avoid C pitfalls. Use software tools to make programs more reliable. Take advantage of existing code libraries. Adopt a sensible set of coding conventions. Such as naming convention Avoid "tricks" and overly complex code. Stick to the standard.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.