Introduction to C Programming CE00312-1 Lecture 1 Introduction to C.

Slides:



Advertisements
Similar presentations
CSE 105 Structured Programming Language (C)
Advertisements

Overview of programming in C C is a fast, efficient, flexible programming language Paradigm: C is procedural (like Fortran, Pascal), not object oriented.
Pemrograman C Risanuri Hidayat. Why C  Compact, fast, and powerful  “Mid-level” Language  Standard for program development (wide acceptance)  It is.
C Programming for engineers Teaching assistant: Ben Sandbank Home page:
CSE1301 Computer Programming Lecture 4: C Primitives I.
Unix Continuum of Tools Do something once: use the command line Do something many times: –Use an alias –Use a shell script Do something that is complex.
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
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 Topics Compilation Using the gcc Compiler
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.
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.
Programming In C++ Spring Semester 2013 Programming In C++, Lecture 1.
CCSA 221 Programming in C CHAPTER 2 SOME FUNDAMENTALS 1 ALHANOUF ALAMR.
CS 11 C track: lecture 1 Preliminaries Need a CS cluster account cgi-bin/sysadmin/account_request.cgi Need to know UNIX ITS.
Welcome In The World Of ‘C’.  TEXT BOOK: Programming in ANCI ‘C By: E Balagurusamy. TMH  Reference Books: 1) The ‘C Programming Language By: Kernighan.
“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.
CSCI 130 Chapter 1. History of C Bell Telephone Laboratories (1972) Dennis Ritchie (also created UNIX) A - B - C.
1 Agenda Administration Background Our first C program Working environment Exercise Memory and Variables.
Programming With C.
1 計算機程式設計 Introduction to Computer Programming Lecture01: Introduction and Hello World 9/10/2012 Slides modified from Yin Lou, Cornell CS2022: Introduction.
History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between Ada.
/* Documentations */ Pre process / Linking statements Global declarations; main( ) { Local Declarations; Program statements / Executable statements; }
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.
1 Programming in C Hello World! Soon I will control the world! Soon I will control the world!
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.
Introduction to C 2008/09/29: Lecture 7 CMSC 104, Section 0101 John Y. Park 1.
CMSC 104, Lecture 111 Introduction to C Topics l Compilation l Using the gcc Compiler l The Anatomy of a C Program l 104 C Programming Standards and Indentation.
Department of Electronic & Electrical Engineering Introduction to C - The Development cycle. Why C? The development cycle. Using Visual Studio ? A simple.
Scott Marino MSMIS Kean University MSAS5104 Programming with Data Structures and Algorithms Week 1 Scott Marino.
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.
MAHENDRAN. Session Objectives Session Objectives  Discuss the Origin of C  Features of C  Characteristics of C  Current Uses of C  “C” Programming.
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
L071 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program Reading Sections
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.
BIL 104E Introduction to Scientific and Engineering Computing Lecture 1.
CSE-102: PROGRAMMING FUNDAMENTALS LECTURE 3: BASICS OF C Course Instructor: Syed Monowar Hossain 1.
Introduction to C Topics Compilation Using the gcc Compiler
UMBC CMSC 104 – Section 01, Fall 2016
CSCE 206 Structured Programming in C
Programming what is C++
Prof: Dr. Shu-Ching Chen TA: Samira Pouyanfar Spring 2017
Computer Science 210 Computer Organization
CSE 220 – C Programming C Fundamentals.
Introduction to C Language
C Programming Hardik H. Maheta.
C Language By Sra Sontisirikit
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.
History of ‘C’ Root of the morden language is ALGOL It’s first
Introduction to C Topics Compilation Using the gcc Compiler
Getting Started with C.
Introduction to C Topics Compilation Using the gcc Compiler
' C ' PROGRAMMING SRM-MCA.
Welcome In The World Of ‘C’.  TEXT BOOK: Programming in ANSI ‘C By: E Balagurusamy. TMH  Reference Books: 1) The ‘C Programming Language By: Kernighan.
Computer Science 210 Computer Organization
Introduction to C Topics Compilation Using the gcc Compiler
Programming Fundamentals Lecture #3 Overview of Computer Programming
2008/09/29: Lecture 7 CMSC 104, Section 0101 John Y. Park
Your first C and C++ programs
C programming Language
Introduction to Computer Programming
Introduction to C Topics Compilation Using the gcc Compiler
An Overview of C.
Introduction to C Topics Compilation Using the gcc Compiler
Introduction to C Programming
Computer Science Department
Presentation transcript:

Introduction to C Programming CE Lecture 1 Introduction to C

Module Structure 2 lectures, 1 Tutorial, 1 Practical per week Module Handbook contains details teaching team class contact, reading list Assessment Web site:- lecture notes and practical exercises AFTER delivery Module handbook to download

Origins of C 1971 Ritchie and Thompson develop Unix written in assembly language This Unix wasn’t portable, a suitable HLL with low level facilities was required CPL had been developed in the 60’s CPL was a large language, later pared down -> BCPL Thompson further reduced BCPL -> B Ritchie enhanced B -> C. Unix was rewritten in C Unix + C became widely available Unix is now portable; any machine with a C compiler can run Unix

C Standards and Variants 1978; Kernighan & Ritchie publish “The C Programming Language” (Traditional C) or K&R C 1990 ANSI Standard (ANSI C) Anything written in traditional C will run on an ANSI C compiler Also available: Borland C, Microsoft C GNU C invoked by the gcc command is a version of ANSI C that runs on UNIX or windows platforms

Characteristics of C Suitable for systems programming Suitable for applications programming C is not a visual language C is not object oriented C supports structured programming functions

The C language C commands are close to machine code Cryptic syntax – programs can be written quickly but can be difficult to read small overheads - fast few safeguards - flexible but dangerous permissive data typing – gives flexibility but reduces the number of errors detected at compilation time can access memory directly using pointers can overflow arrays

Why study the C language? Most widely used programming language. Many application areas real time systems Lots of employment prospects. Other languages have developed from C: C++, Visual C++, Java, C#……. writing C code forces you to think about programming fundamentals Most common example of procedural programming paradigm.

Developing a C Program Fully understand the problem Design a solution Test Implement in C suitable programming language Test Release Maintain

Steps in implementation of C programs Editing: using an editor program, write the code Preprocessing and Compiling translate the C source code into a form that can be executed the output produced by the compiler is called the object program Linking: combine all of the intrinsic functions and individual object files into a single program ready for execution Running run the object program

Overall Structure of a C program # include DEFINITION OF ANY CONSTANTS int main(void) /* some explanatory comment */ { DECLARATIONS STATEMENTS return 0; }

A Simple C program #include /* A simple C program*/ main () { printf(“Hello, world.\n”); }

Expressions and Statements A section of code such as n1+n2 is called an expression A statement is a step in a program An expression becomes a statement when it is terminated by a semicolon

Comments /* An example of a C comment */ A multiline comment can also be used: /* This is a multiline comment. Indentation is not compulsory but it makes the code more readable */ // In some versions this comment can be used

The preprocessor The C preprocessor replaces the line #include with the contents of the header file stdio.h C header files end with the suffix “.h” The C preprocessor also removes the line /* A simple C program*/ because it is a comment On many systems the preprocessor is built into the compiler All preprocessor commands or compiler directives start with #

Statements All C programs must contain a main() function definition. main() is the entry point for the program. Like all function definitions, main() is delimited by curly braces { } should contain one or more statements. Statements are what do things (“perform actions”) in C. printf prints something on the standard output.

C is a compiled language!!! Once a program is written in C, it cannot be executed without further translation on the computer. source program=>machine language this is unlike interpreted languages where each statement in the source code is translated individually and executed immediately in compiled languages such as C all the statements are translated before being executed

The Pre-Processor CPure C Object Code C Compiler Pre- processor Object code is executed when the program runs

A simple C program #include #define PI 3.14 int main(void) /*calculates the area and the */ /*circumference of a circle of radius 3 */ { int radius; float circum, area; radius=3; circum=2*PI*radius; area=PI*radius*radius; printf(“circumference %f\n”, circum); printf(“area %f\n”, area); return 0; }

Output (printf statements) The printf statement consists of any text to be printed plus a format specifier for each argument Format Specifiers: %d, %6d, %f, %6.2f, %ld, %lf, %c, %s Special Character Constants for use in control strings; \nnewline \ttab \\backslash \’single quote