computer programming. topic: structure of c programming

26
COMPUTER PROGRAMMING

Upload: william-payne

Post on 19-Jan-2018

229 views

Category:

Documents


1 download

DESCRIPTION

LECTURE # 03 BY:HIRA FARMAN

TRANSCRIPT

Page 1: COMPUTER PROGRAMMING. Topic: STRUCTURE OF C PROGRAMMING

COMPUTER PROGRAMMING

Page 2: COMPUTER PROGRAMMING. Topic: STRUCTURE OF C PROGRAMMING

Topic:

STRUCTURE OF C PROGRAMMING

Page 3: COMPUTER PROGRAMMING. Topic: STRUCTURE OF C PROGRAMMING

LECTURE # 03

BY:HIRA FARMAN

Page 4: COMPUTER PROGRAMMING. Topic: STRUCTURE OF C PROGRAMMING

STRUCTURE OF C PROGRAMMING

1. C's character set 2. C's keywords 3. Pre-processor commands4. Functions5. Comments6. Layout Of C Program.

Page 5: COMPUTER PROGRAMMING. Topic: STRUCTURE OF C PROGRAMMING

STRUCTURE OF C PROGRAMMINGC CHRACTER SETS:• C does not use, nor requires the use of, every character

found on a modern computer keyboard. The only characters required by the C Programming Language are as follows:

• A - Z• a -z• 0 - 9• space . , : ; ' $ "• # % & ! _ {} [] () $$$$ &&&& |• + - / * =

Page 6: COMPUTER PROGRAMMING. Topic: STRUCTURE OF C PROGRAMMING

STRUCTURE OF C PROGRAMMING

• Keywords• C makes use of only 32 keywords which

combine with the formal syntax to the form the C programming language.

Page 7: COMPUTER PROGRAMMING. Topic: STRUCTURE OF C PROGRAMMING

STRUCTURE OF C PROGRAMMING

• Preprocessor Commands : These commands tells the compiler to do preprocessing before doing actual compilation.

• The first line of the program #include <stdio.h> is a preprocessor command, which tells a C compiler to include stdio.h file before going to actual compilation.

Page 8: COMPUTER PROGRAMMING. Topic: STRUCTURE OF C PROGRAMMING

STRUCTURE OF C PROGRAMMING

• Functions: are main building blocks of any C Program.

• Every C Program will have one or more functions and there is one mandatory function which is called main() function.

• This function is prefixed with keyword int which means this function returns an integer value when it exits. This integer value is returned using return statement or sometimes we use prefixed keyword void.

Page 9: COMPUTER PROGRAMMING. Topic: STRUCTURE OF C PROGRAMMING

STRUCTURE OF C PROGRAMMING

• Comments: are used to give additional useful information inside a C Program. All the comments will be put inside /*...*/ as given in the example above. A comment can span through multiple lines.

Page 10: COMPUTER PROGRAMMING. Topic: STRUCTURE OF C PROGRAMMING

STRUCTURE OF C PROGRAMMING• main() is a function.• In a c program there can be multiple

functions. To begin with, we would concentrate on only those programs which have only one function. The name of this function has to be main(),it cannot be anything else.

• All statements that belongs to main() are enclosed within a pair of braces{} as shown below.

Page 11: COMPUTER PROGRAMMING. Topic: STRUCTURE OF C PROGRAMMING

STRUCTURE OF C-PROGRAMvoid main()

{Statement1;Statement2;Statement3;

.

.

.}

Page 12: COMPUTER PROGRAMMING. Topic: STRUCTURE OF C PROGRAMMING

Header Files:•The files that are specified in the include section is called header files.•These are precompiled files that has some functions define in them.•Header file is given an extention.h•C source file is given an extention.c

Page 13: COMPUTER PROGRAMMING. Topic: STRUCTURE OF C PROGRAMMING

1-Simple C-Program

#include <stdio.h>#include<conio.h> void main() { /* My first program */ printf("Hello, World! \n");}

Page 14: COMPUTER PROGRAMMING. Topic: STRUCTURE OF C PROGRAMMING

2-Simple C-Program#include <stdio.h>#include<conio.h> void main() { /* My 2nd program */ printf("Hello, World! \n");printf(“Hello!\n”);printf(“I am student!\n”);printf(“c is my favorite language!\n”);}

Page 15: COMPUTER PROGRAMMING. Topic: STRUCTURE OF C PROGRAMMING

Function getch()first getch() is a function already defined in the <stdio.h>

It’s C library function.

getch() the name of the function is made up of two things "get" which simply mean get and "ch" which mean character...so in simple terms..it mean "get a character from keyboard buffer

if you didn't use the getch(), you won't able to see the result of the program..

It stops the console screen.

Page 16: COMPUTER PROGRAMMING. Topic: STRUCTURE OF C PROGRAMMING

Use Of Function getch()

Your program will finish running and terminate itself after computing and displaying. But you won't be able to see the output. For that, just to stop there, so that you can see the output, we use getch().

Page 17: COMPUTER PROGRAMMING. Topic: STRUCTURE OF C PROGRAMMING

Use Of Function Clrscr()

• Another C library function.• Clears the contents present in the screen.

Page 18: COMPUTER PROGRAMMING. Topic: STRUCTURE OF C PROGRAMMING

NOTE:

• C is a case sensitive programming language. • C has a free-form line structure. End of each C

statement must be marked with a semicolon.• White Spaces (i-e tab space and space bar )

are ignored.

Page 19: COMPUTER PROGRAMMING. Topic: STRUCTURE OF C PROGRAMMING

Borland Turbo C(The integrated development environment)

Turbo C is an Integrated Development Environment (IDE) and compiler for the C programming language from Borland. First introduced in 1987, it was noted for its integrated development environment, small size, fast compile speed, comprehensive manuals and low price.

Page 20: COMPUTER PROGRAMMING. Topic: STRUCTURE OF C PROGRAMMING

•If you are beginner you would be better off using a simple compiler Turbo C or Turbo c++.Once you have mastered the language elements you can then switch over to more sophisticated compilers like Visual C++.

• The IDE provides an almost ideal environment for learning C.

Page 21: COMPUTER PROGRAMMING. Topic: STRUCTURE OF C PROGRAMMING

Integrated Development Environment(IDE)

• SCREEN SHORTS

Page 22: COMPUTER PROGRAMMING. Topic: STRUCTURE OF C PROGRAMMING
Page 23: COMPUTER PROGRAMMING. Topic: STRUCTURE OF C PROGRAMMING
Page 24: COMPUTER PROGRAMMING. Topic: STRUCTURE OF C PROGRAMMING
Page 25: COMPUTER PROGRAMMING. Topic: STRUCTURE OF C PROGRAMMING
Page 26: COMPUTER PROGRAMMING. Topic: STRUCTURE OF C PROGRAMMING

SUMMARY # 03:

• Write all 32 keywords used in C programming?• Summarized Today's lecture and write 1o

points as your choice.