Programming Languages and Paradigms

Slides:



Advertisements
Similar presentations
C Language.
Advertisements

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
Programming Languages and Paradigms The C Programming Language.
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.
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.
CS 117 Spring 2002 Review for Exam 2 March 6, 2002 open book, 1 page of notes.
1 Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation –The new operator –The delete operator –Dynamic.
Computer Science 210 Computer Organization Introduction to C.
Chapter 3 Control Flow Ku-Yaw Chang Assistant Professor, Department of Computer Science and Information Engineering Da-Yeh University.
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.
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.
Programming Languages and Paradigms Programming C++ Classes.
CPS120: Introduction to Computer Science Decision Making in Programs.
Programming Languages and Paradigms Imperative Programming.
Loops cause a section of a program to be repeated a certain number of times. The repetition continues while a condition remains true. When a condition.
Computer Organization and Design Pointers, Arrays and Strings in C Montek Singh Sep 18, 2015 Lab 5 supplement.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
C LANGUAGE Characteristics of C · Small size
Lecturer: Nguyen Thi Hien Software Engineering Department Home page: hienngong.wordpress.com Chapter 2: Language C++
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
Data Types In Text: Chapter 6.
Computer Organization and Design Pointers, Arrays and Strings in C
Test 2 Review Outline.
The Machine Model Memory
Computer Science 210 Computer Organization
Pointers & Arrays 1-d arrays & pointers 2-d arrays & pointers.
Chapter 6: Data Types Lectures # 10.
Control Structures Combine individual statements into a single logical unit with one entry point and one exit point. Used to regulate the flow of execution.
Java Primer 1: Types, Classes and Operators
C Programming Tutorial – Part I
Java for Android is specific
Learning C Language.
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
Programmazione I a.a. 2017/2018.
Arrays in C.
Programming Languages and Paradigms
11/10/2018.
Advanced Programming Behnam Hatami Fall 2017.
Computer Science 210 Computer Organization
Chapter 3 Introduction to Classes, Objects Methods and Strings
C Stuff CS 2308.
7 Arrays.
Java - Data Types, Variables, and Arrays
An Introduction to Java – Part I, language basics
Pointers, Dynamic Data, and Reference Types
The University of Adelaide, School of Computer Science
CSC215 Lecture Flow Control.
CSC215 Lecture Control Flow.
Classes and Objects.
CPS120: Introduction to Computer Science
Homework Any Questions?.
C Programming Getting started Variables Basic C operators Conditionals
7 Arrays.
C Programming Lecture-8 Pointers and Memory Management
Programming Languages and Paradigms
Programming Languages and Paradigms
ENERGY 211 / CME 211 Lecture 5 October 1, 2008.
CSC215 Lecture Control Flow.
Pointers, Dynamic Data, and Reference Types
Presentation transcript:

Programming Languages and Paradigms The C Programming Language

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 <stdio.h> ) 6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved.

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.

Composite Types Arrays Structures 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.

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.

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

Statements expression-statement Block or compound-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.

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.

Statements (loops) while-statement do-while-statement for-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.

Statements (others) break; continue; return-statement 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.

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.

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.

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