Introduction to c
This presentation is the property of its rightful owner.
Sponsored Links
1 / 15

Introduction to C PowerPoint PPT Presentation


  • 56 Views
  • Uploaded on
  • Presentation posted in: General

Introduction to C. CMSC 104, Section 4 Richard Chang. History of Programming Languages & C. Machine code (aka “binary”) Somehow enter raw sequence of binary patterns 1011010111001011 1011010110101010 Assembly “language” Gave human-friendly syntax to machine code: MOV1200, R0

Download Presentation

Introduction to C

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Introduction to c

Introduction to C

CMSC 104, Section 4

Richard Chang


History of programming languages c

History of Programming Languages & C

  • Machine code (aka “binary”)

    • Somehow enter raw sequence of binary patterns

      1011010111001011

      1011010110101010

  • Assembly “language”

    • Gave human-friendly syntax to machine code:

      MOV1200, R0

      SUB1202, R0

      MOVR0, 1200


History of programming languages c1

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))


History of c

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


History of c1

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


Hello world

Hello World ...

  • C:

    • main( ) {printf("hello, world");}

  • COBOL:

    • MAIN SECTIONDISPLAY “hello, world“STOP RUN.

  • Fortran77:

    • PROGRAM HELLOPRINT*, ‘hello, world‘END

  • Lisp:

    • (defun helloworld ()(print “hello, world") )

  • English:

    • Hello, world.

  • Spanish:

    • Hola mundo

  • French:

    • Salut le Monde

  • Greek:

    • Γεια σου κόσμε


Writing c programs

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.


A simple c program

A Simple C Program

  • One of the first C program examples

    • main ( ) {

    • printf (“hello, world”) ;

    • }


A simple c program to a computer

A Simple C Program…to a Computer

  • So, after a C source file has been created, the programmer must invoke the C compiler before the program can be executed (run).


3 stages of compilation

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

Program Development Using gcc

Editor

Source File pgm.c

Preprocessor

Modified Source Code in RAM

Compiler

Program Object Code File pgm.o

Other Object Code Files (if any)

Linker

Executable File a.out


Anatomy of a c program

Anatomy of a C Program

  • program header comment

  • preprocessor directives (if any)

  • main ( )

  • {

  • statement(s)

  • }


Program header comment

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.


Preprocessor directives

Preprocessor Directives

  • Lines that begin with a # in column 1 are called preprocessor directives (commands).

  • Example: #include <stdio.h>

    • tells the compiler that you want to use functions like printf().


Introduction to c

main ( )

Source code for the program go between the curly braces { } after main()

main() {

/* source code goes here... */

// and comments too!

}


  • Login