CSC215 Lecture Introduction.

Slides:



Advertisements
Similar presentations
Overview of programming in C C is a fast, efficient, flexible programming language Paradigm: C is procedural (like Fortran, Pascal), not object oriented.
Advertisements

Lecture 2 Introduction to C Programming
Introduction to C Programming
 2005 Pearson Education, Inc. All rights reserved Introduction.
Introduction to C Programming
Introduction to C Programming CE Lecture 1 Introduction to C.
C Programming Language 4 Developed in 1972 by Dennis Ritchie at AT&T Bell Laboratories 4 Used to rewrite the UNIX operating system 4 Widely used on UNIX.
CS1061 C Programming Lecture 2: A Few Simple Programs A. O’Riordan, 2004.
1 Key Concepts:  Why C?  Life Cycle Of a C program,  What is a computer program?  A program statement?  Basic parts of a C program,  Printf() function?
1 ICS103 Programming in C Lecture 2: Introduction to C (1)
Guide To UNIX Using Linux Third Edition
Introduction to C Programming
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
C Programming. Chapter – 1 Introduction Study Book for one month – 25% Learning rate Use Compiler for one month – 60%
Copyright 2003 Scott/Jones Publishing Brief Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
Computer Science 210 Computer Organization Introduction to C.
“C” Programming Language CIS 218. Description C is a procedural languages designed to provide lowlevel access to computer system resources, provide language.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
Introduction of C++ language. C++ Predecessors Early high level languages or programming languages were written to address a particular kind of computing.
C Programming language
Programming With C.
History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between Ada.
CMSC 104, Version 9/011 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program 104 C Programming Standards and Indentation.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 2 Chapter 2 - Introduction to C Programming.
Programming Fundamentals. Today’s Lecture Why do we need Object Oriented Language C++ and C Basics of a typical C++ Environment Basic Program Construction.
Course Title: Introduction to C++ Course Instructor: ADEEL ANJUM Chapter No: 01 1 BY ADEEL ANJUM (MCS, CCNA,WEB DEVELOPER)
1 Programming in C Hello World! Soon I will control the world! Soon I will control the world!
Computer Programming I Hour 2 - Writing Your First C Program.
Programming Fundamentals. Overview of Previous Lecture Phases of C++ Environment Program statement Vs Preprocessor directive Whitespaces Comments.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 2 - Introduction to C Programming Outline.
Introduction to C Programming
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
Chapter 1 slides1 What is C? A high-level language that is extremely useful for engineering computations. A computer language that has endured for almost.
INTRODUCTION TO PROGRAMING System Development Mansoura October 2015.
Introduction to C Programming I Subject: T0016 – ALGORITHM AND PROGRAMMING Year: 2013.
BIL 104E Introduction to Scientific and Engineering Computing Lecture 1.
1 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
History of C and basics of Programming
Definition of the Programming Language CPRL
UMBC CMSC 104 – Section 01, Fall 2016
CSCE 206 Structured Programming in C
Programming what is C++
The Machine Model Memory
Prof: Dr. Shu-Ching Chen TA: Samira Pouyanfar Spring 2017
Computer Science 210 Computer Organization
Chapter 1.2 Introduction to C++ Programming
Introduction to C Language
Chapter 2 - Introduction to C Programming
C Programming Hardik H. Maheta.
C Language VIVA Questions with Answers
History of ‘C’ Root of the morden language is ALGOL It’s first
ICS103 Programming in C Lecture 3: Introduction to C (2)
Getting Started with C.
Prof: Dr. Shu-Ching Chen TA: Samira Pouyanfar Hector Cen Fall 2017
CSC215 Lecture Introduction.
C Basics.
Introduction to C Programming Language
Chapter 2 - Introduction to C Programming
C++ History C++ was designed at AT&T Bell Labs by Bjarne Stroustrup in the early 80's Based on the ‘C’ programming language C++ language standardised in.
Choice of Programming Language
Computer Science 210 Computer Organization
CSC215 Lecture Introduction.
CSC215 Lecture Introduction.
Govt. Polytechnic,Dhangar
Introduction C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell.
Programming Fundamentals Lecture #3 Overview of Computer Programming
The C Language: Intro.
C – Programming Language
An Overview of C.
Introduction to C Programming
Presentation transcript:

CSC215 Lecture Introduction

Outline Programming Languages What is C? Writing C Programs Object Oriented Programming Procedural Programming What is C? Short history Features, Strengths and weaknesses Relationships to other languages Writing C Programs Editing Compiling Structure of C Programs Comments Variables Functions: main, function prototypes and functions Expressions and Statements

Programming Languages Many programming languages exist, each intended for a specific purpose Over 700 programming language entries on wikipedia Should we learn all? Which is the best language? None! Choose the right tool for the job based on: problem scope, target hardware/software, memory and performance considerations, portability, concurrency.

Object Oriented Programming Very useful to organize large software projects The program is organized as classes The data is broken into ‘objects’ and the sequence of commands becomes the interactions between objects: Decide which classes you need provide a full set of operations for each class and make commonality explicit by using inheritance. Covered in CSC111 and CSC113

Procedural Programming The program is divided up into subroutines a.k.a procedures a.k.a functions ... Allows code to become structured The programmer must think in terms of actions: decide which procedures and data structures you want Procedural languages include: Fortran BASIC Pascal C

What is C? History: In this course: ANSI/ISO C (C89/C90) 1972 - Dennis Ritchie – AT&T Bell Laboratories 16-bit DEC PDP-11 computer (right) 1978 - Published; first specification of language 1989 - C89 standard (known as ANSI C or Standard C) 1990 - ANSI C adopted by ISO, known as C90 1999 - C99 standard: mostly backward-compatible, not completely implemented in many compilers 2007 - work on new C standard C1X announced In this course: ANSI/ISO C (C89/C90)

What is C? Features: Provides low -level access to memory Provides language constructs that map efficiently to machine instructions Few keywords (32 in ANSI C) Structures, unions – compound data types Pointers - memory, arrays External standard library – I/O, other facilities Compiles to native code Systems programming: OSes, like Linux microcontrollers: automobiles and airplanes embedded processors: phones, portable electronics, etc. digital audio and TV systems . . . Macro preprocessor Widely used today, Extends to newer system architectures

What is C? Strengths: Efficiency: intended for applications where assembly language had traditionally been used Portability: hasn’t splintered into incompatible dialects; small and easily written Power: large collection of data types and operators Flexibility: not only for system but also for embedded system commercial data processing Standard library

What is C? Weaknesses Error-prone: Error detection left to the programmer Difficult to understand Large programs Difficult to modify Memory management Memory management is left to the programmer

Relationship to Other Languages More recent derivatives: C++, Objective C, C# Influenced: Java, Perl, Python (quite different) C lacks: Exceptions Range-checking Memory management and garbage collection. Objects and object-oriented programming Polymorphism Shares with Java: /* Comments */ Variable declarations if / else statements for / while loops function definitions (like methods) Main function starts program

C Program Editing: Compiling: C source code files has .c extension Text files that can be edited using any text editor: Example product.c #include <stdio.h> int main() { int a, b, c; a = 3; b = 2; c = a * b; printf(“The product is %d”, c); } Compiling: gcc -o product product.c “-o” place the output in file product “product” is the executable file To execute the program: product on windows or ./product on Linux and Linux-like

Structure of .c File /* Begin with comments about file contents */ /* Insert #include statements and preprocessor definitions */ /* Function prototypes and variable declarations */ /* Define main() function { Function body } */ /* Define other function(s) {

Structure of .c File: Comments /∗ this is a simple comment ∗/ Can span multiple lines /∗ This comment Spans m u l t i p l e l i n e s ∗/ Completely ignored by compiler Can appear almost anywhere| /∗ h e l l o . c − our f i r s t C program Created for CSC215 ∗/

Structure of .c File: #include Preprocessor #include is a preprocessor: Header files: constants, functions, other declarations #include: read the contents of the header file stdio.h: standard I/O functions for console and files #include <stdio.h> /∗ basic I/O facilities */ stdio.h – part of the C Standard Library other important header files: assert.h ctype.h errno.h float.h limits.h locale.h math.h signal.h setjmp.h stdarg.h stddef.h stdlib.h string.h time.h

Structure of .c File: #Variables and Constants Variables: named spaces in memory that hold values Refer to these spaces using their names rather than memory addresses Names selection adheres to some rules Defined with a type that determines their domains and operations Variable must be declared prior to their use Can change their values after initialization Constants: Do not change their values after initialization Can be of any basic data type Declared by assigning a literal to a typed name, with the use of the keyword const const int LENGTH = 10; Const char NEWLINE = '\n'; Can also use the #define preprocessor #define LENGTH 10 #define NEWLINE '\n'

Structure of .c File: Function Prototype Functions also must be declared before use Declaration called function prototype Function prototypes: int factorial(int); int factorial(int n); Prototypes for many common functions in header files for C Standard Library General form: return_type function_name(arg1,arg2,...); Arguments: local variables, values passed from caller Return value: single value returned to caller when function exits void – signifies no return value/arguments, ex: int rand(void);

Structure of .c File: Function main main(): entry point for C program Simplest version: no inputs, outputs 0 when successful, and nonzero to signal some error: int main(void); Two-argument form of main(): More later !

Structure of .c File: Function Definitions Function declaration <return_type> <function_name>(<list_of_parameters>){ <declare_variables;> <program_statements;> return <expression>; } Must match prototype (if there is one) variable names in arguments don’t have to match No semicolon at end Curly braces define a block – region of code Variables declared in a block exist only in that block Variable declarations before any other statements

Console Input and Output stdout, stdin: console output and input streams puts(<string_expression>): prints string to stdout putchar(<char_expression>): prints character to stdout <char_var> = getchar(): returns character from stdin <string_var> = gets(): reads line from stdin into string printf(control_string, arg1, arg2, …) to be discussed later

Structure of .c File: Expressions and statements a sequence of characters and symbols that can be evaluated to a single data item. consists of: literals, variables, subexpressions, interconnected by one or more operators Numeric literals like 3 or 4.5 String literals like “Hello” Example expressions: Binary arithmetic x+y , x-y , x*y , x/y , x%y Statement: A sequence of characters and symbols causes the computer to carry out some definite action Not all statements have values Example statement: y = x+3∗x/(y−4); Semicolon ends statement (not newline)

Output Statements /∗ The main ( ) function ∗/ int main (void)/∗ entry point ∗/ { /∗ write message to console ∗/ puts( "Hello World!" ); return 0; /∗ exit (0 => success) ∗/ } puts(<string>): output text to console window (stdout) and end the line String literal: written surrounded by double quotes return 0; exits the function with success, returning value 0 to caller