Our First Meeting with - PowerPoint PPT Presentation

About This Presentation
Title:

Our First Meeting with

Description:

... (American National Standards Institute) ... ( First C Program ); } A ... are written in C/C++ History of C C became popular after a book written by Ritchie ... – PowerPoint PPT presentation

Number of Views:156
Avg rating:3.0/5.0
Slides: 47
Provided by: A83477
Learn more at: https://www.oocities.org
Category:
Tags: ansi | book | first | meeting

less

Transcript and Presenter's Notes

Title: Our First Meeting with


1
C
2
History of C
  • 1950 FORTRAN (Formula Translator)
  • 1959 COBOL (Common Business Oriented Language)
  • 1971 Pascal
  • Between 1970-1980 - Ada

3
History of C
  • 1967 BCPL
  • By Martin Richards
  • For writing OS and compilers
  • 1970 B
  • Used to write UNIX OS for DEC PDP-7
  • 1972 C
  • By Dennis Ritchie
  • Used to write UNIX OS for DEC PDP-11
  • Now almost all OS are written in C/C

4
History of C
  • C became popular after a book written by Ritchie
    and Kernighan
  • The C Programming Language
  • Many variations came up for different platforms
  • ANSI (American National Standards Institute)
    approved a standard in 1989

5
Programming Tools
  • Compiler
  • Standard Library
  • IDE
  • Help files documentations

6
Compilers
  • What does it do?
  • Parse the code
  • Tokenize
  • Match syntax
  • Find Errors
  • Prepare object code

7
Standard Library
  • What does it do?
  • Provide implementations of some basic and
    important functions
  • Usually these functions are very efficient
  • Programmers should use library functions to
    improve performance and portability

8
IDE - Integrated Development Environment
  • Helps to Write
  • Use different color to highlight different type
    of code
  • Sometimes shows hints
  • Helps to Compile
  • Set environment variables
  • Linking with libraries

9
IDE - Integrated Development Environment
  • Helps to Debug
  • Execute step by step
  • Use breaks
  • Watch the values of variables
  • Helps to Run

10
Help Files and Documentation
  • Provide details about
  • Syntax
  • Keywords
  • Library functions
  • Examples
  • Etc.

11
C Files
  • Source File
  • .c
  • Contains the code
  • A program may use multiple source files
  • Object File
  • .obj
  • Compiled source file

12
C Files
  • Header File
  • .h
  • Contains codes of library functions
  • We can also write header files
  • Library File
  • .lib
  • Compiled library function

13
C Files
  • Executable File
  • .exe
  • Final program
  • Backup File
  • .bak
  • Other Files

14
Lifecycle of a C Program
Source File
User defined Header File
Standard Header File
Compile
Compile
Compile
Library File
Object File
Link
Executable File
15
A first look at C
  • include ltstdio.hgt
  • void main(void)
  • printf(First C Program)

16
A first look at C
  • include ltstdio.hgt
  • void main(void)
  • printf(First C Program)
  • include
  • Must be written first
  • Means we want to include or use the functions
    defined in the header

17
A first look at C
  • include ltstdio.hgt
  • void main(void)
  • printf(First C Program)
  • include
  • symbol indicates a preprocessor
  • It means it has to be done before compilation

18
A first look at C
  • include ltstdio.hgt
  • void main(void)
  • printf(First C Program)
  • ltstdio.hgt
  • Name of the header file
  • You must know which header you need
  • Use help and documentation to find out

19
A first look at C
  • include ltstdio.hgt
  • void main(void)
  • printf(First C Program)
  • ltstdio.hgt
  • Enclosed in lt gt (header in default place)
  • May be enclosed in (header is in the same
    folder as the source)

20
A first look at C
  • include ltstdio.hgt
  • void main(void)
  • printf(First C Program)
  • main
  • Every C program must have a main function
  • Program starts from the 1st line in main

21
A first look at C
  • include ltstdio.hgt
  • void main(void)
  • printf(First C Program)
  • main
  • Functions has parameters enclosed in ( )
  • Functions may return values

22
A first look at C
  • include ltstdio.hgt
  • void main(void)
  • printf(First C Program)
  • The curly braces are like containers
  • The code between two braces are called a block

23
A first look at C
  • include ltstdio.hgt
  • void main(void)
  • printf(First C Program)
  • Missing either brace will generate compile error
  • Compound Statement missing

24
A first look at C
  • include ltstdio.hgt
  • void main(void)
  • printf(First C Program)
  • printf
  • A function given in stdio.h
  • Prints the text given as the parameter

25
A first look at C
  • include ltstdio.hgt
  • void main(void)
  • printf(First C Program)
  • (semicolon)
  • Every C statement must end with a
  • Otherwise compiler will generate an error
  • Statement Missing

26
A first look at C
  • include ltstdio.hgt
  • void main(void)
  • printf(First C Program)
  • Keywords
  • The texts in White are keywords
  • These are words that has special meanings for C

27
Another Example
  • / My second C Program/
  • include ltstdio.hgt
  • void main(void)
  • printf(My Second C Program\n)

// main function
\n
//end of code
28
Another Example
  • / My second C Program/
  • Enclosed within / and /
  • This is a multi-line Comment
  • It is not part of the code
  • Compiler ignores it
  • Used for helping the programmer to understand the
    code better

29
Another Example
  • // main function
  • This is a single-line Comment

30
Another Example
  • \n
  • This is an escape sequence
  • \ is escape character
  • It indicates that printf should do something
    different with the character that follows the \

31
Another Example
  • \n
  • \n new line (like an enter key)
  • \t tab
  • \a alert (the PC speaker gives a beep)
  • \\ \ (to print \)
  • \ (to print or )

32
Yet Another Example
  • include ltstdio.hgt
  • void main(void)
  • int a // declaring a variable
  • a 10 // assign a value
  • printf(The Value of a is d, a)

33
Yet Another Example
  • int a
  • int is a keyword
  • It means that the variable declared here is an
    integer
  • So int defines the data type
  • C has many data types

34
Yet Another Example
  • int a
  • a is the variable name
  • The statement creates/defines a new variable
    named a
  • Creating a variable means reserving a memory
    location for it
  • The size of the memory needed depends on the data
    type

35
Yet Another Example
  • a 10
  • This is an assignment statement
  • This means the value 10 is written in the
    memory location reserved for a
  • Before using a variable or assigning a value, we
    have to define it first
  • Or a compile error Unknown identifier/
    Undefined Symbol will occur

36
Yet Another Example
  • printf(The Value of a is d, a)
  • This is the way a variables value can be
    outputted
  • The first parameter is format control string.
  • The format and layout of output text is defined
    here

37
Yet Another Example
  • printf(The Value of a is d, a)
  • d is a conversion specifier
  • It tells the printf function that it has to print
    the value of an integer variable here

38
Yet Another Example
  • printf(The Value of a is d, a)
  • The second parameter tells the printf function
    the value that should be printed in place of the
    d

39
Todays Last Example
  • include ltstdio.hgt
  • void main(void)
  • int a // declaring a variable
  • printf(Please enter value of a)
  • scanf(d, a) // inputs a value
  • printf(\nThe Value of a is d, a)

40
Todays Last Example
  • scanf(d, a)
  • scanf is another function given in stdio.h
  • It is used to take inputs from the user
  • Syntax is similar to printf

41
Todays Last Example
  • scanf(d, a)
  • NOTE
  • Here the variable name is preceded by symbol.
  • It indicates the address of the memory location
    that was reserved for a
  • Omitting the symbol will cause wrong results

42
Looking Back
  • We learned about the history of C
  • We learned what tools is needed for software
    development
  • We learned the important files associated with C

43
Looking Back
  • Every C Code begins with the include directive
  • Every C Program must contain one and only one
    function named main
  • A program should have comments to make it easy to
    understand

44
Looking Back
  • Variables must be defined before they can be used
  • printf is used to output
  • scanf for input
  • We learned about escape sequence
  • We also learned about conversion specifier

45
Looking Back
  • We learned about a few compile errors
  • Statement missing
  • Compound Statement missing
  • Unknown identifier

46
Start Practicing
Write a Comment
User Comments (0)
About PowerShow.com