history of c 1950 – fortran (formula translator) 1959 – cobol (common business oriented...
TRANSCRIPT
![Page 1: History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between 1970-1980 - Ada](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649ec05503460f94bcc17f/html5/thumbnails/1.jpg)
![Page 2: History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between 1970-1980 - Ada](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649ec05503460f94bcc17f/html5/thumbnails/2.jpg)
History of CHistory of C• 1950 – FORTRAN (Formula
Translator)
• 1959 – COBOL (Common Business Oriented Language)
• 1971 – Pascal
• Between 1970-1980 - Ada
![Page 3: History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between 1970-1980 - Ada](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649ec05503460f94bcc17f/html5/thumbnails/3.jpg)
History of CHistory 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++
![Page 4: History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between 1970-1980 - Ada](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649ec05503460f94bcc17f/html5/thumbnails/4.jpg)
History of CHistory 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
![Page 5: History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between 1970-1980 - Ada](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649ec05503460f94bcc17f/html5/thumbnails/5.jpg)
Programming ToolsProgramming Tools• Compiler
• Standard Library
• IDE
• Help files & documentations
![Page 6: History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between 1970-1980 - Ada](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649ec05503460f94bcc17f/html5/thumbnails/6.jpg)
CompilersCompilers• What does it do?–Parse the code
–Tokenize
–Match syntax
–Find Errors
–Prepare object code
![Page 7: History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between 1970-1980 - Ada](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649ec05503460f94bcc17f/html5/thumbnails/7.jpg)
Standard LibraryStandard 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
![Page 8: History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between 1970-1980 - Ada](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649ec05503460f94bcc17f/html5/thumbnails/8.jpg)
IDE - Integrated Development IDE - Integrated Development EnvironmentEnvironment
• Helps to Write–Use different color to highlight
different type of code
–Sometimes shows hints
• Helps to Compile–Set environment variables
–Linking with libraries
![Page 9: History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between 1970-1980 - Ada](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649ec05503460f94bcc17f/html5/thumbnails/9.jpg)
IDE - Integrated Development IDE - Integrated Development EnvironmentEnvironment
• Helps to Debug–Execute step by step
–Use breaks
–Watch the values of variables
• Helps to Run
![Page 10: History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between 1970-1980 - Ada](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649ec05503460f94bcc17f/html5/thumbnails/10.jpg)
Help Files and DocumentationHelp Files and Documentation
• Provide details about –Syntax
–Keywords
–Library functions
–Examples
–Etc.
![Page 11: History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between 1970-1980 - Ada](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649ec05503460f94bcc17f/html5/thumbnails/11.jpg)
C Files C Files • Source File– .c
–Contains the code
–A program may use multiple source files
• Object File– .obj
–Compiled source file
![Page 12: History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between 1970-1980 - Ada](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649ec05503460f94bcc17f/html5/thumbnails/12.jpg)
C Files C Files • Header File– .h
–Contains codes of library functions
–We can also write header files
• Library File– .lib
–Compiled library function
![Page 13: History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between 1970-1980 - Ada](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649ec05503460f94bcc17f/html5/thumbnails/13.jpg)
C Files C Files • Executable File– .exe
–Final program
• Backup File– .bak
• Other Files
![Page 14: History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between 1970-1980 - Ada](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649ec05503460f94bcc17f/html5/thumbnails/14.jpg)
Lifecycle of a C ProgramLifecycle of a C Program
SourceFile
User definedHeader File
StandardHeader File
Object File
Compile Compile
Library File
Compile
ExecutableFile
Link
![Page 15: History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between 1970-1980 - Ada](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649ec05503460f94bcc17f/html5/thumbnails/15.jpg)
A first look at CA first look at C
# include <stdio.h>
void main(void)
{
printf(“First C Program”);
}
![Page 16: History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between 1970-1980 - Ada](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649ec05503460f94bcc17f/html5/thumbnails/16.jpg)
A first look at CA first look at C
# include <stdio.h>
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
![Page 17: History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between 1970-1980 - Ada](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649ec05503460f94bcc17f/html5/thumbnails/17.jpg)
A first look at CA first look at C
# include <stdio.h>
void main(void){
printf(“First C Program”);}
# include• # symbol indicates a preprocessor
• It means it has to be done before compilation
![Page 18: History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between 1970-1980 - Ada](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649ec05503460f94bcc17f/html5/thumbnails/18.jpg)
A first look at CA first look at C
# include <stdio.h>void main(void){
printf(“First C Program”);}
<stdio.h>• Name of the header file
• You must know which header you need
• Use help and documentation to find out
![Page 19: History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between 1970-1980 - Ada](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649ec05503460f94bcc17f/html5/thumbnails/19.jpg)
A first look at CA first look at C
# include <stdio.h>void main(void){
printf(“First C Program”);}
<stdio.h>• Enclosed in < > (header in default place)
• May be enclosed in “ ” (header is in the same folder as the source)
![Page 20: History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between 1970-1980 - Ada](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649ec05503460f94bcc17f/html5/thumbnails/20.jpg)
A first look at CA first look at C# include <stdio.h>
void main(void)
{
printf(“First C Program”);
}
main• Every C program must have a ‘main’
function
• Program starts from the 1st line in ‘main’
![Page 21: History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between 1970-1980 - Ada](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649ec05503460f94bcc17f/html5/thumbnails/21.jpg)
A first look at CA first look at C# include <stdio.h>
void main(void)
{
printf(“First C Program”);
}
main• Functions has parameters enclosed in ( )
• Functions may return values
![Page 22: History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between 1970-1980 - Ada](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649ec05503460f94bcc17f/html5/thumbnails/22.jpg)
A first look at CA first look at C# include <stdio.h>void main(void)
{printf(“First C Program”);
}
{ }• The curly braces are like containers
• The code between two braces are called a block
![Page 23: History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between 1970-1980 - Ada](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649ec05503460f94bcc17f/html5/thumbnails/23.jpg)
A first look at CA first look at C# include <stdio.h>void main(void)
{printf(“First C Program”);
}
{ }• Missing either brace will generate
compile error– “Compound Statement missing”
![Page 24: History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between 1970-1980 - Ada](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649ec05503460f94bcc17f/html5/thumbnails/24.jpg)
A first look at CA first look at C# include <stdio.h>
void main(void)
{
printf(“First C Program”);
}
printf• A function given in stdio.h
• Prints the text given as the parameter
![Page 25: History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between 1970-1980 - Ada](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649ec05503460f94bcc17f/html5/thumbnails/25.jpg)
A first look at CA first look at C# include <stdio.h>
void main(void)
{
printf(“First C Program”);}
“ ; ” (semicolon)• Every C statement must end with a ;
• Otherwise compiler will generate an error– “Statement Missing”
![Page 26: History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between 1970-1980 - Ada](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649ec05503460f94bcc17f/html5/thumbnails/26.jpg)
A first look at CA first look at C# include <stdio.h>
void main(void)
{
printf(“First C Program”);
}
Keywords• The texts in White are keywords
• These are words that has special meanings for C
![Page 27: History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between 1970-1980 - Ada](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649ec05503460f94bcc17f/html5/thumbnails/27.jpg)
Another ExampleAnother Example/* My second C Program*/
# include <stdio.h>
void main(void)
{
printf(“My Second C Program\n”);
}//end of code
\n
// main function
![Page 28: History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between 1970-1980 - Ada](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649ec05503460f94bcc17f/html5/thumbnails/28.jpg)
Another ExampleAnother 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
![Page 29: History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between 1970-1980 - Ada](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649ec05503460f94bcc17f/html5/thumbnails/29.jpg)
Another ExampleAnother Example// main function
• This is a single-line Comment
![Page 30: History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between 1970-1980 - Ada](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649ec05503460f94bcc17f/html5/thumbnails/30.jpg)
Another ExampleAnother Example\n
• This is an escape sequence
• ‘\’ is escape character
• It indicates that printf should do something different with the character that follows the \
![Page 31: History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between 1970-1980 - Ada](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649ec05503460f94bcc17f/html5/thumbnails/31.jpg)
Another ExampleAnother Example\n
• \n = new line (like an ‘enter’ key)
• \t = tab
• \a = alert (the PC speaker gives a beep)
• \\ = \(to print \)
• \” = “ (to print “ or ” )
![Page 32: History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between 1970-1980 - Ada](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649ec05503460f94bcc17f/html5/thumbnails/32.jpg)
Yet Another ExampleYet Another Example# include <stdio.h>
void main(void)
{
int a; // declaring a variable
a = 10; // assign a value
printf(“The Value of a is = %d”, a);
}
![Page 33: History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between 1970-1980 - Ada](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649ec05503460f94bcc17f/html5/thumbnails/33.jpg)
Yet Another ExampleYet Another Exampleint 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
![Page 34: History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between 1970-1980 - Ada](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649ec05503460f94bcc17f/html5/thumbnails/34.jpg)
Yet Another ExampleYet Another Exampleint 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
![Page 35: History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between 1970-1980 - Ada](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649ec05503460f94bcc17f/html5/thumbnails/35.jpg)
Yet Another ExampleYet Another Examplea = 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
![Page 36: History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between 1970-1980 - Ada](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649ec05503460f94bcc17f/html5/thumbnails/36.jpg)
Yet Another ExampleYet Another Exampleprintf(“The Value of a is = %d”, a);
• This is the way a variable’s value can be outputted
• The first parameter is format control string.–The format and layout of output text is
defined here
![Page 37: History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between 1970-1980 - Ada](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649ec05503460f94bcc17f/html5/thumbnails/37.jpg)
Yet Another ExampleYet Another Exampleprintf(“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
![Page 38: History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between 1970-1980 - Ada](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649ec05503460f94bcc17f/html5/thumbnails/38.jpg)
Yet Another ExampleYet Another Exampleprintf(“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”
![Page 39: History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between 1970-1980 - Ada](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649ec05503460f94bcc17f/html5/thumbnails/39.jpg)
Today’s Last ExampleToday’s Last Example# include <stdio.h>
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);
}
![Page 40: History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between 1970-1980 - Ada](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649ec05503460f94bcc17f/html5/thumbnails/40.jpg)
Today’s Last ExampleToday’s Last Examplescanf(“%d”, &a);
• scanf is another function given in stdio.h
• It is used to take inputs from the user
• Syntax is similar to printf
![Page 41: History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between 1970-1980 - Ada](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649ec05503460f94bcc17f/html5/thumbnails/41.jpg)
Today’s Last ExampleToday’s Last Examplescanf(“%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
![Page 42: History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between 1970-1980 - Ada](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649ec05503460f94bcc17f/html5/thumbnails/42.jpg)
Looking BackLooking 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
![Page 43: History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between 1970-1980 - Ada](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649ec05503460f94bcc17f/html5/thumbnails/43.jpg)
Looking BackLooking 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
![Page 44: History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between 1970-1980 - Ada](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649ec05503460f94bcc17f/html5/thumbnails/44.jpg)
Looking BackLooking 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
![Page 45: History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between 1970-1980 - Ada](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649ec05503460f94bcc17f/html5/thumbnails/45.jpg)
Looking BackLooking Back• We learned about a few
compile errors–Statement missing
–Compound Statement missing
–Unknown identifier
![Page 46: History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between 1970-1980 - Ada](https://reader036.vdocuments.site/reader036/viewer/2022062408/56649ec05503460f94bcc17f/html5/thumbnails/46.jpg)