Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to C Programming

Similar presentations


Presentation on theme: "Introduction to C Programming"— Presentation transcript:

1 Introduction to C Programming
Lecture 2

2 Today’s Lecture Software Categories System Software
Application Software Introduction to ‘C’ Language History Evolution Justification Development Environment of ‘C’

3 There are two main categories of software
System software Application Software

4 Technology Without An Interesting Name
TWAIN Technology Without An Interesting Name

5 Evolution of programming languages
The lack of portability between different computers led to the development of high-level languages—so called because they permitted a programmer to ignore many low-level details of the computer's hardware Details of procedural, non-procedural will follow in the lectures

6 How people used to program
Machine Language….. Damn! It was difficult Assembly Language…. Remember ADD? Required too much user involvement To much to remember Less semantic C Language B Language.. Bell Labs Improved to C Language Is a compiled language

7 ANSI C

8 Tools of the trade Editor Interpreter and Compilers Debuggers

9 Integrated Development Environment (IDE)
It contains Editor Compilers Debugger Linkers Loaders

10 Loader puts program in memory.
Preprocessor program processes the code. Loader puts program in memory. CPU takes each instruction and executes it, possibly storing new data values as the program executes. Compiler creates object code and stores it on disk. Linker links the object code with the libraries Loader Primary Memory Compiler Editor Preprocessor Linker . Disk CPU Program is created in the editor and stored on disk.

11 #include <iostream.h>
main ( ) { cout << “ Welcome to NIIT “; }

12 Variable X Variable

13 Variable Pic of the memory 25 10323 name of the variable

14 Variable Variable starts with Character Underscore _ (Not Recommended)

15 Variable Small post box X

16 Variable Variable is the name of a location in the memory e.g. x= 2;

17 Variable In a program a variable has: Name Type Size Value

18 Assignment Operator = x = 2 X 2

19 Assignment Operator L.H.S = R.H.S. X+ 3 = y + 4 Wrong Z = x +4
x +4 = Z Wrong

20 10 X X = 10 ; X = 30 ; 30 X

21 X = X + 1; X 10 + 1 = 11 X

22 Data type i int i ; //Declaration line

23 Writing C program

24 Examples of C/C++ compilers of today:
Compiler converts human readable language to a language which is understandable by the operating system/hardware Examples of C/C++ compilers of today: Visual C++ GCC/G++ DJGPP (open source for windows like GCC) Borland C Turbo (obsolete and not recommended)

25 3 Stages of Compilation Stage 1: Preprocessing
Performed by a program called the preprocessor Modifies the source code (in RAM) according to preprocessor directives (preprocessor commands) embedded in the source code Strips comments and white space from the code The source code as stored on disk is not modified.

26 3 Stages of Compilation (con’t)
Stage 2: Compilation Performed by a program called the compiler Translates the preprocessor-modified source code into object code (machine code) Checks for syntax errors and warnings Saves the object code to a disk file, if instructed to do so (we will not do this). If any compiler errors are received, no object code file will be generated. An object code file will be generated if only warnings, not errors, are received.

27 Object code: It is machine language code containing various calls specific to operating system… e.g the object code written by compiler is not only hardware dependent but also operating system dependent. So if you have linux and windows both operating systems then object file of compiled by one Operating System (OS) will not get executed on the other OS

28 3 Stages of Compilation (con’t)
Stage 3: Linking Combines the program object code with other object code to produce the executable file. The other object code can come from the Run-Time Library, other libraries, or object files that you have created. Saves the executable code to a disk file. On the Linux system, that file is called a.out. If any linker errors are received, no executable file will be generated.

29 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

30 #include <iostream.h> //This is pre-processor directive
void main ( ) //this tells the starting point of your program { int x ; int y ; int z ; x = 10 ; y = 20 ; z = x + y ; cout << " x = " ; //print the text on monitor cout << x ; cout << " y = " ; cout << y ; cout << " z =x + y = " ; cout << z ; }

31 int x, y, z ; int x; int y; int z ;

32 Data Types int short long float double char

33 Arithmetic operators Plus + Minus - Multiply * Divide / Modulus %

34 Arithmetic operators i + j x * y a / b a % b

35 % = Remainder 5 % 2 = 1 2 % 2 = 0

36 4 / 2 = 2 5 / 2 = ?

37 Precedence Highest: ( ) Next: * , / , % Lowest: + , -

38 Another C++ Program /*****************************************
** File: proj1.c ** Author: Joe Student ** Date: 9/15/01 ** SSN: ** Section: 0304 ** ** ** This program prompts the user for two integer values then displays ** their product. ***********************************************/

39 Another C Program (con’t)
#include <stdio.h> int main( void ) { int value1, value2, product ; cout<<“Enter two integer values: ; cin>>value1>>value2; product = value1 * value2 ; cout<<“Product = ”<<product ; return 0 ; }

40 Tokens The smallest element in the C language is the token.
It may be a single character or a sequence of characters to form a single item.

41 Tokens are: Tokens can be: Numeric constants Character constants
String constants Keywords Names (identifiers) Punctuation Operators

42 Numeric Constants Numeric constants are an uninterrupted sequence of digits (and may contain a period). They never contain a comma. Examples: 123 98.6

43 Character Constants Singular! One character defined character set.
Surrounded on the single quotation mark. Examples: ‘A’ ‘a’ ‘$’ ‘4’

44 String Constants A sequence characters surrounded by double quotation marks. Considered a single item. Examples: “UMBC” “I like ice cream.” “123” “CAR” “car”

45 Keywords Sometimes called reserved words.
Are defined as a part of the C language. Can not be used for anything else! Examples: int while for

46 Names Sometimes called identifiers.
Can be of anything length, but on the first 31 are significant (too long is as bad as too short). Are case sensitive: abc is different from ABC Must begin with a letter and the rest can be letters, digits, and underscores. Must follow the standards for this course!

47 Punctuation Semicolons, colons, commas, apostrophes, quotation marks, braces, brackets, and parentheses. ; : , ‘ “ [ ] { } ( )

48 Operators There are operators for: assignments mathematical operations
relational operations Boolean operations bitwise operations shifting values calling functions subscripting obtaining the size of an object obtaining the address of an object referencing an object through its address choosing between alternate subexpressions


Download ppt "Introduction to C Programming"

Similar presentations


Ads by Google