L2 - Basic C Elements - CS1010E Programming Methodology...

Info iconThis preview shows pages 1–12. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CS1010E Programming Methodology Basic C Elements The building blocks of C…. Lecture Overview Overview of C language Run Cycle Basic C Elements Various Statements Programming Styles [ CS1010E AY1112S1 Le cture 2 ] 2 C Language: A brief history C Programming Language Originally designed by Dennis Ritchie in 1972 The 1978 book “The C Programming Language” by Brian Kernighan and Dennis Ritchie Gave the first specification of the language Standardized: in 1990: ANSI C ( ISO C, C89/C90 ) The most widespread version Used in this course Evolved: in 1999: C99 3 [ CS1010E AY1112S1 Le cture 2 ] C Language: Characteristics C Programming language is a: Compiled language Program written in C ( source code ) must be compiled into machine code ( executable ) Using C Compiler High Level Programming Language Follow a set of rules (grammar) to express algorithm General purpose language Imperative language 4 [ CS1010E AY1112S1 Le cture 2 ] Run Cycle for Compiled Language Run Cycle: The process of writing, compiling and executing a program Writing • Tool: Editor • Produce: Source Code Compiling • Tool: Compiler • Produce: Executable Executing • Tool: None • Produce: Result Compilation Error Runtime Error Logic Error 5 [ CS1010E AY1112S1 Le cture 2 ] Environment and Tools in this Course Environment: Cygwin : Emulate Linux (Unix-like) under Windows Tools: Editor: vim , nano , etc (You only need one) Compiler: gcc (GNU C Compiler) Comments and Rationale: Tools look primitive but very flexible and powerful Explicitly show the run cycle step by step 6 [ CS1010E AY1112S1 Le cture 2 ] Run Cycle: Writing a Program Use an editor to write a program following C syntax Using vim editor under cygwin 7 [ CS1010E AY1112S1 Le cture 2 ] Run Cycle: Compiling the Source Code Use a compiler to translate C Source Code into Machine Code Source code with syntax errors will fail to compile Known as Compilation Errors Using gcc compiler under cygwin 8 [ CS1010E AY1112S1 Le cture 2 ] Run Cycle: Executing the Executable The executable can be directly executed May terminate unexpectedly due to errors Runtime Error May terminate successfully but give the wrong result Logic Error A successful run of the an executable 9 [ CS1010E AY1112S1 Le cture 2 ] Run Cycle: A reminder Run Cycle happens in the “Implementation” step of the problem solving process You should have designed the before you attempt to write the program Analysis Design Implementation Testing Writing •Tool: Editor •Produce: Source Code Compiling •Tool: Compiler •Produce: Executable Executing •Tool: None •Produce: Result 10 [ CS1010E AY1112S1 Le cture 2 ] Your very first C Program The famous “Hello World!” program Simple program to show a message on screen #include <stdio.h> int main( ) { printf(" Hello World!\n "); return 0; } Preprocessor Directive Main function function body 11 [ CS1010E AY1112S1 Le cture 2 ] C Elements:...
View Full Document

Page1 / 46

L2 - Basic C Elements - CS1010E Programming Methodology...

This preview shows document pages 1 - 12. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online