CSE 105 Structured Programming Language (C)

Slides:



Advertisements
Similar presentations
Chapter 11 Introduction to Programming in C
Advertisements

Agenda Definitions Evolution of Programming Languages and Personal Computers The C Language.
Overview of programming in C C is a fast, efficient, flexible programming language Paradigm: C is procedural (like Fortran, Pascal), not object oriented.
C Language.
Fundamentals of Computer and programming in C Programming Languages, Programs and Programming Rohit Khokher.
IT 325 OPERATING SYSTEM C programming language. Why use C instead of Java Intermediate-level language:  Low-level features like bit operations  High-level.
Senem Kumova Metin // FALL CS115 Introduction to Programming Inst. Senem Kumova Metin Textbook : A Book on C, A. Kelly.
BBS Yapısal Programlama (Structured Programming)
Senem Kumova Metin Introduction to Programming CS 115 Introduction to Computing PART I : Computer Basics PART II: Introduction to Computing/Programming.
CS115 Introduction to Programming
Copyright © 2002 W. A. Tucker1 Chapter 1 Lecture Notes Bill Tucker Austin Community College COSC 1315.
COSC 120 Computer Programming
Introduction to C Programming CE Lecture 1 Introduction to C.
Introduction to C (Reek, Chs. 1-2) 1CS 3090: Safety Critical Programming in C.
Wednesday, 9/4/02, Slide #1 1 CS 106 Intro to CS 1 Wednesday, 9/4/02  Today: Introduction, course information, and basic ideas of computers and programming.
B-1 Lecture 2: Problems, Algorithms, and Programs © 2000 UW CSE University of Washington Computer Programming I.
1 Lecture 1  Getting ready to program  Hardware Model  Software Model  Programming Languages  The C Language  Software Engineering  Programming.
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
Starting Out with C++: Early Objects 5/e © 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5 th Edition Chapter 1 Introduction.
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.
C programming Language and Data Structure For DIT Students.
Introduction to C. A Brief History Created by Dennis Ritchie at AT&T Labs in 1972 Originally created to design and support the Unix operating system.
‘C’ LANGUAGE PRESENTATION.  C language was introduced by Dennis Ritchie..  It is a programming language, which can make a interaction between user and.
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
Copyright 2003 Scott/Jones Publishing Brief Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
COMPUTER PROGRAMMING. Introduction to C++ History Merges notions from Smalltalk and notions from C The class concept was borrowed from Simular67 Developed.
By: Mr. Baha Hanene Chapter 3. Learning Outcomes We will cover the learning outcome 02 in this chapter i.e. Use basic data-types and input / output in.
Computer Science 210 Computer Organization Introduction to C.
CS102 Introduction to Computer Programming
Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 1 Introduction to Computers and Programming.
“C” Programming Language What is language ? Language is medium of communication. If two persons want to communicate with each other, they have to use.
Introduction to C Programming. A Brief History u Created by Dennis Ritchie at AT&T Labs in 1972 u Originally created to design and support the Unix operating.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming 1.
1 Computing Software. Programming Style Programs that are not documented internally, while they may do what is requested, can be difficult to understand.
Programming With C.
History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between Ada.
King Saud University College of applied studies and community services CSC 1101 Computer Programming I Lecture 2.
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.
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)
C Programming language Basic Concepts Prepared By The Smartpath Information systems
Algorithms  Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
I Power Higher Computing Software Development Development Languages and Environments.
Chapter 1 Computers, Compilers, & Unix. Overview u Computer hardware u Unix u Computer Languages u Compilers.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
Agenda Computer Languages How to Write a Simple C Program
CMPE13Cyrus Bazeghi 1 Chapter 11 Introduction to Programming in C.
Brief Version of Starting Out with C++ Chapter 1 Introduction to Computers and Programming.
Scott Marino MSMIS Kean University MSAS5104 Programming with Data Structures and Algorithms Week 1 Scott Marino.
Introduction to C Programming Language. History of C  C was evolved by Dennis Ritchie at AT&T Bell Laboratories in early of 1970s  Successor of: ALGOL.
Chapter 11  Getting ready to program  Hardware Model  Software Model  Programming Languages  Facts about C++  Program Development Process  The Hello-world.
An overview of C Language. Overview of C C language is a general purpose and structured programming language developed by 'Dennis Ritchie' at AT &T's.
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
Chapter 1: Introduction to Computers and Programming.
L071 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program Reading Sections
INTRODUCTION TO PROGRAMING System Development Mansoura October 2015.
UMBC CMSC 104 – Section 01, Fall 2016
Computer Science 210 Computer Organization
Algorithms Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
Choice of Programming Language
Overview of Computers & Programming Languages
Computer Science 210 Computer Organization
פרטים נוספים בסילבוס של הקורס
2008/09/29: Lecture 7 CMSC 104, Section 0101 John Y. Park
Introduction to Computer Programming
Introduction to Computer Programming
The C Language: Intro.
Introduction to C (Reek, Chs. 1-2)
Presentation transcript:

CSE 105 Structured Programming Language (C) Introduction CSE 105 Structured Programming Language (C)

Programming Languages Machine Language Binary code Low level Assembly Language Pneumonic per binary code Structured Programming Language (Fortran, Basic) Program is a set of procedures Mid level Modular Programming Language (C, Pascal ) Application is set of Modules – consisting of related procedures Object Oriented Programming Language (C++, Java ) World is composed of entities objects – consisting of data and behavior high level Scripting Languages (Python, Awk) Logic Programming (Prolog ) English like construction Focus on task not on programming Application-specific

C: History This requires low-level access to the underlying hardware: Developed in the 1970s – in conjunction with development of UNIX operating system When writing an OS kernel, efficiency is crucial This requires low-level access to the underlying hardware: e.g. programmer can leverage knowledge of how data is laid out in memory, to enable faster data access UNIX originally written in low-level assembly language – but there were problems: No structured programming (e.g. encapsulating routines as “functions”, “methods”, etc.) – code hard to maintain Code worked only for particular hardware – not portable

C: Characteristics C takes a middle path between low-level assembly language… Direct access to memory layout through pointer manipulation Concise syntax, small set of keywords … and a high-level programming language like Java: Block structure Some encapsulation of code, via functions Type checking (pretty weak)

C: Dangers C is not object oriented! C has portability issues Can’t “hide” data as “private” or “protected” fields You can follow standards to write C code that looks object-oriented, but you have to be disciplined – will the other people working on your code also be disciplined? C has portability issues Low-level “tricks” may make your C code run well on one platform – but the tricks might not work elsewhere The compiler and runtime system will rarely stop your C program from doing stupid/bad things Compile-time type checking is weak No run-time checks for array bounds errors, etc. like in Java

Separate compilation A C program consists of source code in one or more files Each source file is run through the preprocessor and compiler, resulting in a file containing object code Object files are tied together by the linker to form a single executable program Source code file1.c Preprocessor/ Compiler Object code file1.obj Source code file2.c Preprocessor/ Compiler Object code file2.oobj Libraries Linker Executable code a.out

Separate compilation Advantage: Quicker compilation When modifying a program, a programmer typically edits only a few source code files at a time. With separate compilation, only the files that have been edited since the last compilation need to be recompiled when re-building the program. For very large programs, this can save a lot of time.

Structure of a Simple C Program #include “stdio.h” #include “stdlib.h” #define CONSTANT_NAME 4 void main(void) { float y=0.1; int x[100]; char name[50]; printf(“\nProgram start”); ………..……. } Header files to be included Definition of any constants used in program Main C Program Section Variable declaration and (optional) initialisation C Program Code

Header File Section #include “header file name” All C programs will contain this section Header files are used by the computer when it is verifying the syntax of your program In your C programs, you will use some standard C commands (functions) that someone else has written the code to implement Examples are the functions to display text on the screen (printf) and to read information typed in from the keyboard (scanf) The contents of the header files listed in your program must contain a description of the valid syntax for such C functions At some point, you may write your own C functions which can be used by any C program in which case you will also have to create an associated header file The syntax for including a header file is #include “header file name”

Definition of Constants This is an optional section in your C file It is highly recommended that if you have to use a constant value in your program that you define it in this section It could save you a lot of time if you ever need to change its value (particularly if it occurs in many places in a long program) The syntax for the definition is #define constant name constant’s value

Definition of Constants It is good programming practice that constant’s names should only contain CAPITAL LETTERS and the _ (underscore) character You can define integer, real or character constants #define INTEGER_CONSTANT 101 #define REAL_CONTANT 3.1427 #define CHARACTER_CONSTANT “hello”

Main C Program Section In simple C programs, this section is always started with the line void main(void) The beginning and end of the main section are delimited by chain brackets - { and } It is good programming practice to indent your code in this section If you have further sub-blocks of code then all the lines of code in these sub-sections should be further indented

Main C Program Section It is good practice to include comments in you C file One comment at the top of the program should provide a general overview of what the C file does Many comments within the file should explain the various steps in the program Comments can be placed either Within the bounds of /* and */ On a single line starting with //

Compilation Process Executable code a.exe Source code file1.c Preprocessor Intermediate C code Object code file1.obj Compiler Your header file2.h Header files stdio.h Source code file2.c Intermediate C code Object code file1.obj Preprocessor Compiler Libraries (e.g. stdio.lib) Linker Executable code a.exe

Execution Environment CPU Input Devices Registers ALU CU Output Devices RAM OS memomry Disk drives Stack Heap Your program Variables / data Executable code Other Programs

References “The C Programming Language” , 2nd Edition, Brian W. Kernighan & Dennis M.Ritchie. Web page … …