CSCI 130 Chapter 2. Program Components main() #include Variable Definition Function Prototype Program Statements Function Call Function Definition Comments.

Slides:



Advertisements
Similar presentations
Introduction to C++ An object-oriented language Unit - 01.
Advertisements

User Defined Functions
C Functions. What are they? In general, functions are blocks of code that perform a number of pre-defined commands to accomplish something productive.
Spring Semester 2013 Lecture 5
Lecture 2 Introduction to C Programming
Introduction to C Programming
 2005 Pearson Education, Inc. All rights reserved Introduction.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line.
Principles of Programming Fundamental of C Programming Language and Basic Input/Output Function 1.
1 ICS103 Programming in C Lecture 3: Introduction to C (2)
1 ICS103 Programming in C Lecture 2: Introduction to C (1)
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
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.
Chapter 3 Getting Started with C++
chap13 Chapter 13 Programming in the Large.
Goals of Course Introduction to the programming language C Learn how to program Learn ‘good’ programming practices.
Chapter 3: Completing the Problem- Solving Process and Getting Started with C++ Introduction to Programming with C++ Fourth Edition.
History of C and C++ C++ evolved from C ANSI C C++ “spruces up” C
GNU Compiler Collection (GCC) and GNU C compiler (gcc) tools used to compile programs in Linux.
Chapter 6: User-Defined Functions
CSCI 130 Chapter 5 Functions. Functions are named uniquely Performs a specific task Is independent –should not interfere with other parts of program May.
Introduction to Programming Using C Modularity. 2 Contents Modularity Functions Preprocessor Comments Global variables.
/* Documentations */ Pre process / Linking statements Global declarations; main( ) { Local Declarations; Program statements / Executable statements; }
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 2 Chapter 2 - Introduction to C Programming.
Array in C++ / review. An array contains multiple objects of identical types stored sequentially in memory. The individual objects in an array, referred.
Fundamentals of C and C++ Programming. EEL 3801 – Lotzi Bölöni Sub-Topics  Basic Program Structure  Variables - Types and Declarations  Basic Program.
Functions Top-down design Breaking a complex problem into smaller parts that we can understand is a common practice. The process of subdividing a problem.
CECS 121 Test 1. Functions allow you to group program statements under one name C and C++ are case-sensitive so main(), MAIN(), and Main() are all different.
CSCI 171 Presentation 2. Program Components main() #include Variable Definition Function Prototype Program Statements Function Call Function Definition.
Control Structures (B) Topics to cover here: Sequencing in C++ language.
CECS 130 EXAM 1. To declare a constant (read only) value: const int x = 20; const float PI = 3.14; Can we do this? const int x;
Slides created by: Professor Ian G. Harris Hello World #include main() { printf(“Hello, world.\n”); }  #include is a compiler directive to include (concatenate)
Chapter 3 Functions. 2 Overview u 3.2 Using C++ functions  Passing arguments  Header files & libraries u Writing C++ functions  Prototype  Definition.
Functions Chapter 6. Modular Programming Modular programming: breaking a program up into smaller, manageable functions or modules Function: a collection.
Functions  A Function is a self contained block of one or more statements or a sub program which is designed for a particular task is called functions.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 2 - Introduction to C Programming Outline.
ECE 103 Engineering Programming Chapter 31 C Scopes Herbert G. Mayer, PSU CS Status 8/1/2015 Initial content copied verbatim from ECE 103 material developed.
Variables  A piece of memory set aside to store data  When declared, the memory is given a name  by using the name, we can access the data that sits.
Computer Programming A simple example /* HelloWorld: A simple C program */ #include int main (void) { printf (“Hello world!\n”); return.
 2007 Pearson Education, Inc. All rights reserved. A Simple C Program 1 /* ************************************************* *** Program: hello_world.
Principles of Programming CSEB134 : BS/ CHAPTER Fundamentals of the C Programming Language.
Building Programs from Existing Information Solutions for programs often can be developed from previously solved problems. Data requirements and solution.
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
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.
CCSA 221 Programming in C CHAPTER 3 COMPILING AND RUNNING YOUR FIRST PROGRAM 1 ALHANOUF ALAMR.
Bill Tucker Austin Community College COSC 1315
Chapter 1.2 Introduction to C++ Programming
CSCE 206 Structured Programming in C
Chapter 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
CHAPTER 2 PART #1 C++ PROGRAM STRUCTURE
Chapter 1.2 Introduction to C++ Programming
Chapter 2 - Introduction to C Programming
Lecture 7: Repeating a Known Number of Times
Chapter 2, Part I Introduction to C Programming
Chapter 2 part #1 C++ Program Structure
ICS103 Programming in C Lecture 3: Introduction to C (2)
C-language Lecture By B.S.S.Tejesh, S.Neeraja Asst.Prof.
Chapter 2 - Introduction to C Programming
User Defined Functions
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
Programs written in C and C++ can run on many different computers
Functions continued.
Chapter 2 - Introduction to C Programming
DATA TYPES There are four basic data types associated with variables:
Introduction to C Programming
Presentation transcript:

CSCI 130 Chapter 2

Program Components main() #include Variable Definition Function Prototype Program Statements Function Call Function Definition Comments

main() Required in every program –Under normal circumstances: program starts at first statement in main program ends at last statement in main –Ex: void main() { printf(“Hello World”); }

#include Instructs C compiler to add contents of another file during compilation #include statements at top of file Usually called header files (.h) –Some supplied with compiler Never modified –Some user defined Can be modified

Example of #include Library function –#include –greater than, less than indicate library function User defined function –#include “myfile.h” –quotation marks indicate user-defined function –if not in same directory as main file, need to specify the path

Variable Definition Variable - name assigned to a data storage location Must define a variable before it can be used Definition informs compiler of: –variable name –type of data Ex: –int a; –char a, b, c;

Program Statements These statements do the ‘Real’ work One per line, end with semi-colon Statements perform various functions: –input/output write to screen/file/printer accept from screen/file –call functions –perform calculations –other

The Function Call ‘Calling a function’ –asking compiler to execute a function outside of the main() function Ex: –printf(“Hello World”); –doReset() –c = product(a,b)

Function Definition A function: is a self contained block of code performs a specific task A function may be: –a library function printf() –a user defined function doMultiply()

Example of a function, and a function call Function: int doMultiply(int x, int y) { return(x*y); } Function call:...programming statements… c = doMultiply(3,6); …programming statements...

Comments When in doubt - Comment!!! No effect on program execution Any text can be stored in a comment May take up part of a line, a whole line, more than one line Do not be stingy with Comments!!!

Examples of Comments Comments may use one line, part of a line, or more than one line: –/*A single line*/ –for (int x; x<10; x++) /*start of a loop*/ –/*Comments can span multiple lines –as well*/

Philosophy You never have too many comments Too few comments may: –cost you points in this class –cost you friends on the job –cause grey hairs Use comments when the logic is fresh in your mind Crucial to program maintenance