Why Use CProgramming Language?
1. C is a powerful and flexible language.
2. It’s a fundamental popular language preferred by
most programmers.
3. C is portable, meaning a C program written in one
computer system can be compiled and run on
another system.
4. Supports Modular Programming Development
Using Functions.
5. Supports Software Reusability.
3.
C Programming DevelopmentLife Cycle. (PDLC)
1. Create Source Code: Series of statements or
commands that instruct the computer to
perform a desired task.
2. Using In- Built Editors: Enter the source code
in to the compiler, e.g. gcc linux editor
3. Compile the Source Code.
4. Linking to create an executable file.
5. Complete the development life cycle.
The Structure ofa C Program
1: #include <stdio.h> // header file
2: main() // beginning of program body
3: { //beginning of program body
4: printf("Hello, World!n"); //Displays Output
5: return 0; // terminate the program normally, return
value 0 to the operating system.
6: } // symbolizes end of program body
6.
Components of aC Program
• Header files: #include<stdio.h>, the #include
instructs the compiler to add contents of the
include file to your program during compilation.
• main(): beginning of program body.
• Variable definition: A variable is a name assigned
to a data storage location.
• Function Prototype*: {Refer to Functions Later}
• Program Statements or lines of code: (as above)
• printf: displays information on the screen output
7.
Cont’d…
• scanf: readsdata from keyboard.
• return: abort program normally and return
control to the operating system.
• comments: /*……*/ or //
• braces: enclose the program body symbolizing
the beginning and end of program body {…}
8.
Variables & Constants
•Storing data in C programs we use variables or
constants.
• Variables: A named data storage location in your
computers memory e.g. a, cal_num. Not
acceptable variables #a, cal num etc.
• Reserved words (Keywords): should never be
used as variables such as the data types,
functions.
• Constants: have defined values e.g. PI = 3.142
9.
C Fundamental NumericData Types
Data Type Keyword*
(C Format !)
Bytes
Required
Range*
Character Char 1 -128 to 127
Integer Int 2 -32768 to 32767
Short integer short int 2 -32768 to 32767
Long integer long int 4 -2,147,483,648 to 2,147,438,647
Unsigned character Unsigned char 1 0 to 255
Unsigned integer Unsigned int 2 0 to 65535
Unsigned short integer Unsigned short int 2 0 to 65535
Unsigned long integer Unsigned long int 4 0 to 4,294,967,295
Single-precision floating-point float 4 1.2E-38 to 3.4E381
Double-precision floating-point double 8 2.2E-308 to 1.8E3082
10.
Variable Declaration
• inta;
• float cal_num;
• Other Keywords (Read!): enum, typedef,
constants, symbolic constants, literal
constants with a const keyword
Note:
• #define PI 3.31412 and int a = 22.4
11.
ASSIGNMENT!!!
In groups of10, prepare short presentations slides (5) to
demonstrate how we use the following compiler to edit, debug
and compile computer programs :
1. BorlandC 4.5 Compiler or Higher Version {5 Marks}
2. Linux Compiler {7 Marks}
Requirements: {Demo [Slide # 5]: Structure of a Program}
Members will be chosen randomly to demonstrate on how these
compilers work on behalf of the entire group.
On presenting you must present list of group members.
Use Microsoft Slides for Presentation/Demo Purposes.
Members from @ group will be selected randomly to represent the
rest of the members.
Deadline: 6th
October 2013
12.
Readings !
• TheFundamental Operators in C Programming
• C Expressions {Simple and Complex}
• Statements in C {Simple and Compound}
• Reserved (Key)Words in C Programming Language
• Order of Precedence in C complex expressions
• Define Variables, Declaration of Variables
• Assigning a value to a Variable
• How do Input and Output values in the Program?
{which functions are used & how?}