1 Programming in C Hello World! Soon I will control the world! Soon I will control the world!

Slides:



Advertisements
Similar presentations
Module 6: Introduction to C Language ITEI102 Introduction to Programming Structure of C++ Program - Programming Terminologies - Microsoft Visual Studio.
Advertisements

Programming In C++ Spring Semester 2013 Lecture 2 Programming In C++, Lecture 2.
11-2 Identify the parts of the “main” function, which include Preprocessor Directives main function header main function body which includes Declaration.
Lecture 2 Introduction to C Programming
Introduction to C Programming
Introduction to C++ Programming. A Simple Program: Print a Line of Text // My First C++ Program #include int main( ) { cout
 C++ programming facilitates a disciplined approach to program design. ◦ If you learn the correct way, you will be spared a lot of work and frustration.
Introduction Kingdom of Saudi Arabia Shaqra University
COSC 120 Computer Programming
Your First C++ Program Aug 27, /27/08 CS 150 Introduction to Computer Science I C++  Based on the C programming language  One of today’s most.
Three types of computer languages
Introduction to C Programming Overview of C Hello World program Unix environment C programming basics.
 2003 Prentice Hall, Inc. All rights reserved. 1 Machine Languages, Assembly Languages, and High-level Languages Three types of computer languages 1.Machine.
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.
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
Using C Programming Language.  The programs that run on a computer are referred to as software.  You’ll learn key programming methodology that are enhancing.
Using C Programming Language.  The programs that run on a computer are referred to as software.  You’ll learn key programming methodology that are enhancing.
Introduction to C++ - How C++ Evolved Most popular languages currently: COBOL, Fortran, C, C++, Java (script) C was developed in 1970s at AT&T (Richie)
Spring 2005, Gülcihan Özdemir Dağ BIL104E: Introduction to Scientific and Engineering Computing, Spring Outline 1.1Introduction 1.2What Is a Computer?
History of C and C++ C++ evolved from C ANSI C C++ “spruces up” C
Computer Engineering 1 nd Semester Dr. Rabie A. Ramadan 2.
Creating your first C++ program
Programming With C.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 1 February 8, 2005.
Programming Fundamentals. Today’s Lecture Why do we need Object Oriented Language C++ and C Basics of a typical C++ Environment Basic Program Construction.
COMPUTER PROGRAMMING. A Typical C++ Environment Phases of C++ Programs: 1- Edit 2- Preprocess 3- Compile 4- Link 5- Load 6- Execute Loader Primary Memory.
CHAPTER 2 PART #1 C++ PROGRAM STRUCTURE 1 st semester H 1 King Saud University College of Applied studies and Community Service Csc 1101 By:
INTRODUCTION Kingdom of Saudi Arabia Princess Nora bint Abdul Rahman University College of Computer Since and Information System CS240.
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.
Chapter 2 part #1 C++ Program Structure
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.
CMSC 1041 Introduction to C Creating your first C program.
CHAPTER 1: INTRODUCTION C++ Programming. CS 241 Course URL: Text Book: C++ How to Program, DETITEL & DEITEL, eighth Edition.
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.
 2003 Prentice Hall, Inc. All rights reserved Basics of a Typical C++ Environment C++ systems –Program-development environment –Language –C++
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
1 8/30/06CS150 Introduction to Computer Science 1 Your First C++ Program.
1 C Syntax and Semantics Dr. Sherif Mohamed Tawfik Lecture Two.
L071 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program Reading Sections
BIL 104E Introduction to Scientific and Engineering Computing Lecture 1.
1 CS 192 Lecture 4 Winter 2003 December 8-9, 2003 Dr. Shafay Shamail.
Introduction to C Topics Compilation Using the gcc Compiler
The Machine Model Memory
Chapter 1: Introduction to computers and C++ Programming
CSC201: Computer Programming
Introduction to C Language
Chapter 2 - Introduction to C Programming
Chapter 2, Part I Introduction to C Programming
Chapter 2 part #1 C++ Program Structure
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.
Computer Engineering 1nd Semester
Introduction to C Topics Compilation Using the gcc Compiler
Getting Started with C.
Introduction to C Topics Compilation Using the gcc Compiler
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
Govt. Polytechnic,Dhangar
Creating your first C program
Chapter 2 - Introduction to C Programming
Programming Fundamentals Lecture #3 Overview of Computer Programming
Introduction to Computer Programming
Programs written in C and C++ can run on many different computers
Capitolo 1 – Introduction C++ Programming
Chapter 2 - Introduction to C Programming
Introduction to C Topics Compilation Using the gcc Compiler
Introduction to C Programming
Chapter 2 part #1 C++ Program Structure
Presentation transcript:

1 Programming in C Hello World! Soon I will control the world! Soon I will control the world!

2 Introduction to C  C language Facilitates a structured and disciplined approach to computer program design Provides low-level access Highly portable

3 Program Basics  The source code for a program is the set of instructions written in a high-level, human readable language. X = 0; MOVE 0 TO X. X := 0  The source code is transformed into object code by a compiler. Object code is a machine usable format.  The computer executes a program in response to a command.

4 Basics of a Typical C Environment Phases of C Programs: 1.Edit 2.Preprocess 3.Compile 4.Link 5.Load 6.Execute Loader Primary Memory Program is created in the editor and stored on disk. Preprocessor program processes the code. Loader puts program in memory. CPU takes each instruction and executes it, possibly storing new data values as the program executes. Compiler Compiler creates object code and stores it on disk. Linker links the object code with the libraries, creates a.out and stores it on disk Editor Preprocessor Linker CPU Primary Memory Disk

5 GCC Program Basics  The basic program writing sequence: 1. create or modify a file of instructions using an editor  Unix: Pico, vi, emacs, … 2. compile the instructions with GCC 3. execute or run the compiled program repeat the sequence if there are mistakes Pico:

6 Structure of a C Program Every C program must have a main function main function function 1 function n

7 Functions  Each function consists of a header followed by a basic block.  General format: fn-name (parameter-list) basic block header

8 The Basic Block A semi-colon (;) is used to terminate a statement A block consists of zero or more statements Nesting of blocks is legal and common  Each interior block may include variable declarations { declaration of variables executable statements }

9 Return statement(p. 126)  return expression 1. Sets the return value to the value of the expression 2. Returns to the caller / invoker  Example:

10 SSH On-Campus SSH to one of the machines in the list machine.cs.clemson.edu Off-Campus SSH to access.cs.clemson.edu ssh machine.cs.clemson.edu

11 Go Tigers!!! Our First Program mkdir cpsc111 cd cpsc111 pico ch03First.c mkdir cpsc111 cd cpsc111 pico ch03First.c

12 Compiling and Running a Program  To compile and print all warning messages, type gcc –Wall prog-name.c  If using math library (math.h), type gcc –Wall –lm prog-name.c  By default, the compiler produces the file a.out

13 Compiling and Running a Program  To execute the program type./a.out The./ indicates the current directory  To specify the file for the object code, for example, p1.o, type gcc –Wall prog1.c –o p1.o then type./p1.o to execute the program

14 Comments  Make programs easy to read and modify  Ignored by the C compiler  Two methods: 1. // - line comment - everything on the line following // is ignored 2. /* */ - block comment - everything between /* */ is ignored

15 Preprocessor Directive: #include  A C program line beginning with # that is processed by the compiler before translation begins.  #include pulls another file into the source causes the contents of the named file, stdio.h, to be inserted where the # appears. Such a file is commonly called a header file. <>’s indicate that it is a compiler standard header file.

16 Introduction to Input/Output  Input data is read into variables  Output data is written from variables.  Initially, we will assume that the user enters data via the keyboard views output data in a terminal window on the screen

17 Program Input / Output  The C run-time system automatically opens two files for you at the time your program starts: stdin – standard input (from the keyboard) stdout – standard output (to the terminal window in which the program started)  Later, how to read and write files on disk 1. Using stdin and stdout 2. Using FILE’s

18 Console Input/Output  Defined in the C library included in Must have this line near start of file: #include Includes input functions scanf, fscanf, … Includes output functions printf, fprintf, …

19 Console Output - printf  Print to standard output, typically the screen  General format (value-list may not be required): printf("format string", value-list);

20 Console Output What can be output?  Any data can be output to display screen  Literal values  Variables  Constants  Expressions (which can include all of above)  Note Values are passed to printf Addresses are passed to scanf

21 Console Output  We can Control vertical spacing with blank lines  Use the escape sequence "\n“, new line Control horizontal spacing  Spaces  Use the escape sequence “\t”, tab Sometimes undependable.

22 Console Output - Examples Sends string "Hello World" to display, skipping to next line Displays the lines Good morning Ms Smith.

23 Program Output: Escape Character \ Indicates that a “special” character is to be output

24 Programming in C T H E E N D