structured programming n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
STRUCTURED PROGRAMMING PowerPoint Presentation
Download Presentation
STRUCTURED PROGRAMMING

Loading in 2 Seconds...

play fullscreen
1 / 46

STRUCTURED PROGRAMMING - PowerPoint PPT Presentation


  • 526 Views
  • Uploaded on

STRUCTURED PROGRAMMING. Introduction to C. The History of C Language. Developed by Dennis Ritchie at Bell Laboratories 1972 Developed on UNIX Operating System. LANGUAGE LEVEL. C is an intermediate to high-level language High level language - English like Low level - machine language

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'STRUCTURED PROGRAMMING' - jaden


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
structured programming

STRUCTURED PROGRAMMING

Introduction to C

the history of c language
The History of C Language
  • Developed by Dennis Ritchie
  • at Bell Laboratories 1972
  • Developed on UNIX Operating System
language level
LANGUAGE LEVEL
  • C is an intermediate to high-level language
  • High level language - English like
  • Low level - machine language
  • C also provides control of hardware a facility not always available with higher level languages
programming environment
Programming Environment
  • C has been a compiled language (each statement is translated into machine language)
  • 5 Steps of Compilation
  • preprocessing
  • translating
  • optimizing
  • assembling
  • link editing
strengths of c
Strengths of C
  • Portability across different systems
  • Efficiency of C Code
  • Ease of Maintenance
  • Control over low-level operations
weakness of c
Weakness of C
  • Syntax is somewhat irregular
  • Operators have context sensitive meanings
  • Allows programmer to bypass the type system, which can be misused.
identifiers or names in c
Identifiers or Names in C
  • Letters a, digits 1, and underscores _
  • start with a letter or underscore _
  • case sensitive A a
  • max. 31 characters
  • not identical to a keyword (void)
  • +: count, first_char,TRUE, char1
    • -: 1st_integer, void, last-time
the character set
The Character Set
  • Uppercase alphabetic characters
  • lowercase alphabetic characters
  • digits
  • punctuation
  • formatting
  • graphic characters
  • ASCII
format of c programs
Format of C Programs
  • Free-Format Language
  • start at a column
  • no special place
  • single or multiple lines of code
whitespace characters
Whitespace Characters
  • Separate identifiers or other elements (tokens)
  • space
  • line feed
  • backspace
  • horizontal tap vertical tap
  • form feed
  • carriage return
token
Token
  • The compiler divides a C program into groups of characters that belong together
  • Each group is a token.
  • ( ) [ ] + -
subprograms or functions
Subprograms or Functions
  • A C program is an collection of subprograms called functions.
  • Function heading/parameters/fct block
  • type function_name
  • {
  • variable declarations
  • code
  • }
shortest c program
Shortest C Program
  • Function with the name main required
  • void because no value is returned
  • void main ( void )
  • {
  • }
calling a function
Calling a Function
  • We will have main() call the function does_nothing
  • void main ( void )
  • {
  • does_nothing () ;
  • }
output in c
Output in C
  • Void main ( void )
  • {
  • printf ( “C” by Discovery\n” ) ;
  • }
output special meaning
Output-Special Meaning
  • \t the tab character
  • \b the backspace character
  • \” the double quote character
  • \’ the single quote character
  • \\ the backslash character
  • \0 the null character
the structured approach
The Structured Approach
  • main ( ) is the driver of the program
  • Each subfunction must be:
  • 1. Be defined
  • 2. Be declared and
  • 3. Be called
input and output with variables
Input and Output with Variables
  • the keyword int is the name for a built-in data type used to represent integers
  • the following declares a variable of type
  • int with the name counter
  • int counter;
  • can be declared inside or outside of a function block
input with scanf keyboard
Input with scanf () keyboard
  • Scanf () converts intput from the ASCII representation entered at the keyboard to the internal representation used by the computer.
  • It is similar to the printf ()
arithmetic operations
Arithmetic Operations
  • +addition and unary plus
  • - unary minus and subtraction
  • * multiplication
  • / division
  • % remainder
  • a = (a/b) *b + (a%b)
precedence of arithmetic operations
Precedence of Arithmetic Operations
  • High Precedence
  • Unary Operators - +
  • Multiplicative Operators * / %
  • Additive Operators + -
  • Assignment Operator =
compound assignment
Compound Assignment
  • The first syntax shortcut is compound assignment
  • The assignment statement
  • a = a + 4
  • can be shortened to
  • a += 4
increment and decrement by 1 operations
Increment and Decrement by 1 Operations
  • Another shortcut in source code is provided for incrementing a variable by one.
  • a = a + 1 ;
  • a += 1 ;
  • a++;
introduction to functions and structured programming
Introduction to Functions and Structured Programming
  • The goals of structured programming include writing source code that is modular in nature, easily modifiable, robust (handles errors gracefully) and readable.
  • A modular program is composed of many independent subprograms or functions in C.
functions subprograms
Functions (Subprograms)
  • Each subprogram or function in C should be designed to do one task
  • and should not be too long to be understood easily.
  • Another programming goal is to write subprograms that are tools and can be used with little or no modifications in many programs
  • Variables and constants declared in it
prepocessor constants
Prepocessor Constants
  • Defining constants add to program’s readability and ease of modification.
  • Preprocessor directives:
  • start with #
  • #include #include <stdio.h>
  • reads external file into source file here
  • #define #define MAXEMPLOYEES 150
function parameters
Function Parameters
  • Using parameters is one method of letting a function communicate with the rest of the program without depending directly on program variables.
  • A function parameter is used to carry information from one function to another.
ansi c function definition
ANSI C Function Definition
  • int f ( int x )
  • The heading will appear before the opening brace for the function.
  • This informs the compiler that the function f takes a single parameter that will be referred to by the name x in the body of the function and that the parameter type is int.
function calls
Function Calls
  • A function call in C consists of the function’s name, and a pair of parentheses containing the actual parameters.
  • A function call can appear anywhere that an expression of the corresponding type is allowed.
  • main ( ) calls f several times
  • f ( ) mathematical function
language elements introduced
Language Elements Introduced
  • Comments
  • Control Statements
  • Conversion Specifications
  • Escape Characters
  • Function Definitions
  • Function Calls
  • Function Declarations
language elements introduced1
Language Elements Introduced
  • Identifiers
  • Library Functions
  • Operators
  • Preprocessor Directives
  • Types
  • Variable Declarations
comments
Comments
  • /* This is a comment. */
control statements
Control Statements
  • return
  • Used to impart value to a function and to return control from a function to the calling environment.
conversion specifications
Conversion Specifications
  • %d conversion to or from decimal
  • %x conversion to or from hexadecimal
  • %o conversion to or from octal
escape character
Escape Character
  • ‘\’
  • escapes the usual meaning of the next character
escape characters examples
Escape CharactersExamples
  • \t the tab character
  • \c a carriage return
  • \b the backspace character
  • \” the double quote character string
  • \’ the single quote character
  • \\ the backslash character
  • \0 the null character
  • \n the newline character
function definitions
Function Definitions
  • Functions must have a heading and function block.
  • The heading contains the function type, a name (identifier), a pair of parentheses, and the formal parameters
  • The function block would contain the declaration of the local variables and the executable code.
function calls1
Function Calls
  • Consists of the function name,
  • a pair of parentheses
  • and a semicolon.
  • Any actual parameters appear between the parentheses.
function declarations
Function Declarations
  • Consist of the function type, the function name, and a pair of parentheses containing the number and type of each parameter.
  • int f( int x ) (ANSI Prototype)
identifiers
Identifiers
  • Consist of letters a, A
  • underscores _
  • numbers 1
  • They must not start with a number and must not conflict with any keyword.
library functions
Library Functions
  • printf ( “control string”, parameters) ;
  • Does format output. Takes one additional parameter for each conversion specification in the control string.
  • scanf ( “control string”, parameters) ;
  • Does formatted input. Takes one additional paramter for each conversion specification in the the control string.
operators
Operators
  • = assignment
  • + addition
  • - unary minus and subtraction
  • * multiplication
  • / division
  • % remainder
operators1
Operators
  • +=, -=, *=, compound assignment
  • /=, %=
  • ++ increment by 1
  • -- decrement by 1
preprocessor directives
Preprocessor Directives
  • #include
  • includes a source file or header file at that point in the code
  • #define
  • used to define constants for easy readability and maintainability
types
Types
  • int
  • used to represent an integer value
  • void
  • indicates that a function will not return a value or that a function does not take parameters.
variable declarations
Variable Declarations
  • Consists of the type name followed by a comma-separated list of variables and a terminating semicolon.
  • int counter;