Programming Languages and Paradigms The C Programming Language.

Slides:



Advertisements
Similar presentations
Chapter 3: Control Flow S. M. Farhad. Statements and Blocks An expression becomes a statement when it is followed by a semicolon Braces { and } are used.
Advertisements

Introduction to C Programming
Introduction to C Programming
C Language.
ICE1341 Programming Languages Spring 2005 Lecture #13 Lecture #13 In-Young Ko iko.AT. icu.ac.kr iko.AT. icu.ac.kr Information and Communications University.
Chapter 6 Type Checking. The compiler should report an error if an operator is applied to an incompatible operand. Type checking can be performed without.
Programming Languages and Paradigms
Statement-Level Control Structures
Programming Paradigms Introduction. 6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1:
What is a pointer? First of all, it is a variable, just like other variables you studied So it has type, storage etc. Difference: it can only store the.
PL/SQL.
Chapter 7: User-Defined Functions II
Chapter 7 User-Defined Methods. Chapter Objectives  Understand how methods are used in Java programming  Learn about standard (predefined) methods and.
Homework Any Questions?. Statements / Blocks, Section 3.1 An expression becomes a statement when it is followed by a semicolon x = 0; Braces are used.
Chapter 10.
Run time vs. Compile time
1 Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation –The new operator –The delete operator –Dynamic.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 7 User-Defined Methods.
Chapter 7: User-Defined Methods
Guide To UNIX Using Linux Third Edition
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009.
Chapter 7: Runtime Environment –Run time memory organization. We need to use memory to store: –code –static data (global variables) –dynamic data objects.
Operator Precedence First the contents of all parentheses are evaluated beginning with the innermost set of parenthesis. Second all multiplications, divisions,
 2006 Pearson Education, Inc. All rights reserved Arrays.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 6 Functions.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Tevfik Bultan Lecture 12: Pointers continued, C strings.
Loops and Iteration for Statements, while Statements and do-while Statements.
/* Documentations */ Pre process / Linking statements Global declarations; main( ) { Local Declarations; Program statements / Executable statements; }
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Learners Support Publications Classes and Objects.
Programming Languages and Paradigms Programming C++ Classes.
CPS120: Introduction to Computer Science Decision Making in Programs.
Programming Languages and Paradigms Imperative Programming.
VARIABLES, CONSTANTS, OPERATORS ANS EXPRESSION
CS 261 – Data Structures Introduction to C Programming.
Slides created by: Professor Ian G. Harris Hello World #include main() { printf(“Hello, world.\n”); }  #include is a compiler directive to include (concatenate)
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Brief Edition Chapter 6 Functions.
Functions Math library functions Function definition Function invocation Argument passing Scope of an variable Programming 1 DCT 1033.
C LANGUAGE Characteristics of C · Small size
 Control Flow statements ◦ Selection statements ◦ Iteration statements ◦ Jump statements.
2: Basics Basics Programming C# © 2003 DevelopMentor, Inc. 12/1/2003.
Chapter 1 Java Programming Review. Introduction Java is platform-independent, meaning that you can write a program once and run it anywhere. Java programs.
CPS120 Introduction to Computer Science Exam Review Lecture 18.
JAVA Programming (Session 2) “When you are willing to make sacrifices for a great cause, you will never be alone.” Instructor: รัฐภูมิ เถื่อนถนอม
1 ENERGY 211 / CME 211 Lecture 3 September 26, 2008.
C++ Lesson 1.
Information and Computer Sciences University of Hawaii, Manoa
Definition of the Programming Language CPRL
Test 2 Review Outline.
Chapter 7 User-Defined Methods.
Programming Languages and Paradigms
BY GAWARE S.R. COMPUTER SCI. DEPARTMENT
C Short Overview Lembit Jürimägi.
Programming Paradigms
Prepared By: G.UshaRani B.Pranalini A.S.Lalitha
Programming Languages and Paradigms
User-Defined Functions
7 Arrays.
Pointers, Dynamic Data, and Reference Types
Classes and Objects.
Homework Any Questions?.
C Programming Getting started Variables Basic C operators Conditionals
2. Second Step for Learning C++ Programming • Data Type • Char • Float
C Programming Lecture-8 Pointers and Memory Management
Programming Languages and Paradigms
Programming Languages and Paradigms
C Language B. DHIVYA 17PCA140 II MCA.
Standard Version of Starting Out with C++, 4th Edition
Presentation transcript:

Programming Languages and Paradigms The C Programming Language

6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L2: C Slide 2 Components of a C Program A C program is a collection of function definitions, (global) variable definitions, declarations and compiler directives Functions ( e.g., void push( char c ) { … } ) Variables ( e.g., int top; char Store[MAX]; ) Declarations ( e.g., void push( char c ); ) Compiler directives ( e.g., #define MAX 100 #include )

6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L2: C Slide 3 Built-in Data Types in C int, char, float Short and long versions of these data types short, long, double, long double, … No explicit boolean type in C Control structures that require conditions expect an int value 0 => false, non-zero => true

6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L2: C Slide 4 Composite Types Arrays Collection of elements of the same type Declaration: type varname[integer-value]; Structures Collection of elements of different types or with different names Declaration: struct strname { field declarations… }; struct strname varname; dot operator: varname.field

6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L2: C Slide 5 Pointers Address operator: & De-referencing operator: * Pointers and arrays Array names as addresses Pointer arithmetic Array access [] Dynamic allocation malloc, free, NULL Multi-dimensional arrays Pointers and structures: the -> operator

6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L2: C Slide 6 Strings String: sequence of characters (stored in a character array) The null (‘\0’) terminator String literals ( e.g., “hello” ) String functions ( ) strcpy strlen strcmp strcat …

6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L2: C Slide 7 Statements expression-statement Expression followed by a semicolon expr; where expr consists of variables, constants, operators, parentheses, function calls Block or compound-statement 0 or more statements enclosed in { } Declarations may precede statements { decl decl decl … stmt stmt stmt }

6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L2: C Slide 8 Statements (decision) if-statement Condition bounded by parentheses Numeric expression expected in condition Optional else clause switch-statement Can be viewed as a special kind of block Has entry points (through the case labels) and exit points (through break; statements ) switch expression should be of ordinal type

6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L2: C Slide 9 Statements (loops) while-statement Loop test at the beginning of the loop Loop body may not be executed at all do-while-statement Loop test at the end of the loop Loop body executed at least once for-statement for( expr1; expr2; expr3 ) stmt Has an equivalent while-loop formulation Used if there is an explicit loop control variable

6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L2: C Slide 10 Statements (others) break; Breaks out of the nearest enclosing loop or switch continue; Proceeds to the loop test return-statement return expr; Provides value return by a function Without expr (if return type is void), the statement simply causes control to be returned to the caller

6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L2: C Slide 11 Functions Function definition: Return type Name Parameters Body (block)

6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L2: C Slide 12 Parameter Passing In C, all parameters are pass by value Pointers and the address operator enable a function to update data outside of the function But the parameter passed (the address) is still a value

6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L2: C Slide 13 Module Organization in C Suppose mod.c is a module containing functions to be used by other C source files A mod.h file contains function prototypes and #define directives An #include directive is placed in the file using the module (i.e., #include “mod.h”). (Do you need to include it in mod.c?) Modules can be separately compiled and then linked with other modules to produce an executable

6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L2: C Slide 14 Scope Names in a { … } block are limited to that block Local variables Formal parameters of a function are local to the function body/block Declarations outside the functions are accessible from other functions extern declaration: compiler permits use of variables before they are defined static definition: variable use restricted to functions within file

6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L2: C Slide 15 Library Functions The C standard library I/O, math, string functions and others Prototypes are in: …