Introduction to C CMSC 104, Section 4 Richard Chang 1.

Slides:



Advertisements
Similar presentations
An Introduction to Programming By :- Vishal Hirani B.Tech II year (CSE)
Advertisements

Introduction to C Programming CE Lecture 1 Introduction to C.
Your First C++ Program Aug 27, /27/08 CS 150 Introduction to Computer Science I C++  Based on the C programming language  One of today’s most.
Software Lesson #1 CS1313 Spring Software Lesson 1 Outline 1.Software Lesson 1 Outline 2.What is Software? A Program? Data? 3.What are Instructions?
Program Flow Charting How to tackle the beginning stage a program design.
1 Key Concepts:  Why C?  Life Cycle Of a C program,  What is a computer program?  A program statement?  Basic parts of a C program,  Printf() function?
1 8/30/06CS150 Introduction to Computer Science 1 Your First C++ Program.
CMSC 104, Version 9/011 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program 104 C Programming Standards and Indentation.
C programming Language and Data Structure For DIT Students.
Introduction to C Topics Compilation Using the gcc Compiler
Introduction to C. A Brief History Created by Dennis Ritchie at AT&T Labs in 1972 Originally created to design and support the Unix operating system.
CHAPTER 1: INTORDUCTION TO C LANGUAGE
Introduction to C/C++ Programming This lecture has major focus on programming, compilation.
CHAPTER 4: INTRODUCTION TO COMPUTER ORGANIZATION AND PROGRAMMING DESIGN Lec. Ghader Kurdi.
Welcome In The World Of ‘C’.  TEXT BOOK: Programming in ANCI ‘C By: E Balagurusamy. TMH  Reference Books: 1) The ‘C Programming Language By: Kernighan.
“C” Programming Language What is language ? Language is medium of communication. If two persons want to communicate with each other, they have to use.
Introduction to C Programming. A Brief History u Created by Dennis Ritchie at AT&T Labs in 1972 u Originally created to design and support the Unix operating.
Spring 2005, Gülcihan Özdemir Dağ BIL104E: Introduction to Scientific and Engineering Computing, Spring Outline 1.1Introduction 1.2What Is a Computer?
Hello World 2 What does all that mean?.
History of C and C++ C++ evolved from C ANSI C C++ “spruces up” C
Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice:
Creating your first C++ program
Programming With C.
History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between Ada.
CMSC 104, Version 9/011 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program 104 C Programming Standards and Indentation.
1 Programming in C Hello World! Soon I will control the world! Soon I will control the world!
Chapter 1 Introduction Chapter 1 Introduction 1 st Semester 2015 CSC 1101 Computer Programming-1.
CS CS CS IA: Procedural Programming CS IB: Object-Oriented Programming.
Algorithms  Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
DOCUMENTATION SECTION GLOBAL DECLARATION SECTION
Introduction to C 2008/09/29: Lecture 7 CMSC 104, Section 0101 John Y. Park 1.
CMSC 104, Lecture 111 Introduction to C Topics l Compilation l Using the gcc Compiler l The Anatomy of a C Program l 104 C Programming Standards and Indentation.
CS Computer Science I. BCPL was developed in 1967 as a language for writing operating systems and software compilers In 1970, the creators of the.
CMSC 1041 Introduction to C Creating your first C program.
Agenda Computer Languages How to Write a Simple C Program
Anatomy of the simplest C Program Sen Zhang SUNY Oneonta Oneonta, NEW YORK © 2004
Department of Electronic & Electrical Engineering Introduction to C - The Development cycle. Why C? The development cycle. Using Visual Studio ? A simple.
First Compilation Rudra Dutta CSC Spring 2007, Section 001.
Computer Programming A simple example /* HelloWorld: A simple C program */ #include int main (void) { printf (“Hello world!\n”); return.
The Functions and Purposes of Translators Translators, Interpreters and Compilers - High Level Languages.
Introduction to C Programming Language. History of C  C was evolved by Dennis Ritchie at AT&T Bell Laboratories in early of 1970s  Successor of: ALGOL.
An overview of C Language. Overview of C C language is a general purpose and structured programming language developed by 'Dennis Ritchie' at AT &T's.
Introduction to C Programming
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
1 8/30/06CS150 Introduction to Computer Science 1 Your First C++ Program.
L071 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program Reading Sections
Software Engineering Algorithms, Compilers, & Lifecycle.
Introduction to C Topics Compilation Using the gcc Compiler
Foundations of Computer Science C & C++ programming lecture 2
UMBC CMSC 104 – Section 01, Fall 2016
Chapter 5- Assembling , Linking, and Executing Programs
CSCI-235 Micro-Computer Applications
Introduction to C Language
C Programming Hardik H. Maheta.
Algorithms Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
History of ‘C’ Root of the morden language is ALGOL It’s first
Introduction to C Topics Compilation Using the gcc Compiler
Introduction to C Topics Compilation Using the gcc Compiler
Welcome In The World Of ‘C’.  TEXT BOOK: Programming in ANSI ‘C By: E Balagurusamy. TMH  Reference Books: 1) The ‘C Programming Language By: Kernighan.
and Executing Programs
Introduction to Computer Programming
Hello World 2 What does all that mean?.
Introduction to C Topics Compilation Using the gcc Compiler
Creating your first C program
2008/09/29: Lecture 7 CMSC 104, Section 0101 John Y. Park
Introduction to Computer Programming
Introduction to C Topics Compilation Using the gcc Compiler
Comparing JavaScript to Other Languages
Computer Organization & Compilation Process
Introduction to C Topics Compilation Using the gcc Compiler
Presentation transcript:

Introduction to C CMSC 104, Section 4 Richard Chang 1

History of Programming Languages & C Machine code (aka “binary”) Somehow enter raw sequence of binary patterns Assembly “language” Gave human-friendly syntax to machine code: MOV1200, R0 SUB1202, R0 MOVR0,

History of Programming Languages & C Early high-level languages COBOL SUBTRACT B FROM A GIVING C MULTIPLY C BY 2 GIVING D FORTRAN S1 = 3.0 S2 = 4.0 H = SQRT((S1 * S1) + (S2 * S2)) 3

History of C Derived from… (wait for it…) “B”! (“B” itself was derived from the BCPL language) Design goals were for C to be: Efficient Close to the machine Structured: A true high-level language with sophisticated control flow, data structures 4

History of C UNIX was recoded in C PDP-11 was a machine with 64 Kilobytes of addressable memory C is written in C! Of course, first versions were written in assembly language 5

Hello World... C: main( ) { printf("hello, world"); } COBOL: MAIN SECTION DISPLAY “hello, world“ STOP RUN. Fortran77: PROGRAM HELLO PRINT*, ‘hello, world‘ END Lisp: (defun helloworld () (print “hello, world") ) English: Hello, world. Spanish: Hola mundo French: Salut le Monde Greek: Γεια σου κόσμε 6

7 Writing C Programs A programmer uses a text editor (not the same as a word processor!) to create or modify files containing C code. Code is also known as source code. A file containing source code is called a source file.

8 A Simple C Program One of the first C program examples 1. main ( ) { 2. printf (“hello, world”) ; 3. }

A Simple C Program… to a Computer main(){\n\tprinf(“ hello,world“);\n } So, after a C source file has been created, the programmer must invoke the C compiler before the program can be executed (run).

10 3 Stages of Compilation Stage 1: Preprocessing combines several text files for the compiler Stage 2: Compiling translates high-level source code into machine language (object code) Stage 2: Linking combines object code from Stage 2 with object code in libraries to create an executable program

Program Development Using gcc 11 Source File pgm.c Program Object Code File pgm.o Executable File a.out Preprocessor Modified Source Code in RAM Compiler Linker Other Object Code Files (if any) Editor

12 Anatomy of a C Program program header comment preprocessor directives (if any) main ( ) { statement(s) }

13 Program Header Comment Comments help a human being understand what the program does. It is customary to include comments at the top of the file that include: the name of the file author purpose of the source code in the file Comments are ignored by the compiler. Comments also appear interspersed in the source code.

14 Preprocessor Directives Lines that begin with a # in column 1 are called preprocessor directives (commands). Example: #include tells the compiler that you want to use functions like printf().

15 main ( ) Source code for the program go between the curly braces { } after main() main() { /* source code goes here... */ // and comments too! }