Topic 3 – The General Form of a C Program. CISC 105 – Topic 3 The General Form of a C Program Now, all of the basic building blocks of a C program are.

Slides:



Advertisements
Similar presentations
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 12P. 1Winter Quarter User-Written Functions.
Advertisements

1 Lecture 16:User-Definded function I Introduction to Computer Science Spring 2006.
Topic 9C – Multiple Dimension Arrays. CISC105 – Topic 9C Multiple Dimension Arrays A multiple dimension array is an array that has two or more dimensions.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 11 – Fundraiser Application: Introducing Scope.
Dale/Weems/Headington
True or false A variable of type char can hold the value 301. ( F )
Topic 9 – Introduction To Arrays. CISC105 – Topic 9 Introduction to Data Structures Thus far, we have seen “simple” data types. These refers to a single.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 14 – Student Grades Application: Introducing.
Topic 2 – Introduction to the C Programming Language.
Topic 9A – Arrays as Function Arguments. CISC105 – Topic 9A Arrays as Function Arguments There are two ways to use arrays as function arguments: Use an.
CS1061 C Programming Lecture 2: A Few Simple Programs A. O’Riordan, 2004.
CS 201 Functions Debzani Deb.
CISC 105 – Topic 2 Last Topic Review Name the principle components of a computer. What advantage does assembly language have over machine language? What.
Topic 4 – Programmer- Defined Functions. CISC 105 – Topic 4 Functions So far, we have only seen programs with one function, main. These programs begin.
Chapter 3 Getting Started with C++
UNIT 3 TEMPLATE AND EXCEPTION HANDLING. Introduction  Program errors are also referred to as program bugs.  A C program may have one or more of four.
Goals of Course Introduction to the programming language C Learn how to program Learn ‘good’ programming practices.
C Functions Programmer-defined functions – Functions written by the programmer to define specific tasks. Functions are invoked by a function call. The.
C++ Basics Structure of a Program. C++ Source Code Plain text file Typical file extension .CPP Must compile the C++ source code without errors before.
CSCI 130 Chapter 5 Functions. Functions are named uniquely Performs a specific task Is independent –should not interfere with other parts of program May.
/* Documentations */ Pre process / Linking statements Global declarations; main( ) { Local Declarations; Program statements / Executable statements; }
COMPUTER PROGRAMMING. Functions What is a function? A function is a group of statements that is executed when it is called from some point of the program.
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
/* C Programming for the Absolute Beginner */ // by Michael Vine #include main() { printf(“\nC you later\n”); system(“pause”); }
How to start Visual Studio 2008 or 2010 (command-line program)
C++ Programming: Basic Elements of C++.
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:
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 6 September 17, 2009.
CPSC 230 Computers and Programming I Spring 2003 Dr. Lynn Lambert.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 7 Clicker Questions September 22, 2009.
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.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 6: User-Defined Functions I.
A First Book of ANSI C, Fourth Edition1 Functions for Modularity 04/24/15.
COMPUTER PROGRAMMING. Functions’ review What is a function? A function is a group of statements that is executed when it is called from some point of.
1 Announcements Note from admins: Edit.cshrc.solaris instead of.tcshrc Note from admins: Do not use delta.ece.
1 COMS 261 Computer Science I Title: Functions Date: October 12, 2005 Lecture Number: 17.
1 Structure of a C Program (continued) Presentation original from Dr. Turner’s class USF - COP C for Engineers Summer 2008.
PHP. PHP User Defined Functions Besides the built-in PHP functions, we can create our own functions. A function is a block of statements that can be used.
Functions: Part 2 of /11/10: Lecture 16 CMSC 104, Section 0101 John Y. Park 1.
Java methods Methods break down large problems into smaller ones Your program may call the same method many times saves writing and maintaining same code.
CHAPTER 10 ARRAYS AND FUNCTIONS Prepared by: Lec. Ghader Kurdi.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 6: User-Defined Functions I.
1 MODULAR DESIGN AND ABSTRACTION. 2 SPECIFYING THE DETAILS OF A PROBLEM INTO A RELATED SET OF SMALLER PROBLEMS.
CS1201: PROGRAMMING LANGUAGE 2 FUNCTIONS. OVERVIEW What is a Function? Function Prototype Vs Decleration Highlight Some Errors in Function Code Parameters.
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.
4.3 Functions. Functions Last class we talked about the idea and organization of a function. Today we talk about how to program them.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 6: User-Defined Functions I.
Lecture-3 Functions and Recursion. C Preprocessor Includes header files like stdio.h Expands macros defined Handles conditional compilations PreprocessorProcessor.
Functions Structured Programming. Topics to be covered Introduction to Functions Defining a function Calling a function Arguments, local variables and.
Repetition Statements (Loops). 2 Introduction to Loops We all know that much of the work a computer does is repeated many times. When a program repeats.
Introduction to Programming Lecture 6. Functions – Call by value – Call by reference Today's Lecture Includes.
Programming Fundamentals Enumerations and Functions.
Functions Chapter 5. Function A set of instructions that are designed to perform specific task. A complete and independent program. It is executed by.
NOTE: C programs consist of functions one of which must be main. C programs consist of functions one of which must be main. Every C program begins executing.
Computer Programming II Lecture 4. Functions - In C++ we use modules to divide the program into smaller and manageable code. These modules are called.
FUNCTIONS (C) KHAERONI, M.SI. OBJECTIVE After this topic, students will be able to understand basic concept of user defined function in C++ to declare.
1 This week Basics of functions Stack frames Stack vs. Heap (brief intro) Calling conventions Storage classes vs. scope Library functions Overloading.
Chapter 9: Value-Returning Functions
Chapter 6: User-Defined Functions I
Chapter 2 part #1 C++ Program Structure
2008/11/10: Lecture 16 CMSC 104, Section 0101 John Y. Park
Functions, Part 2 of 3 Topics Functions That Return a Value
Introduction to C Topics Compilation Using the gcc Compiler
Writing Functions.
Introduction to C Topics Compilation Using the gcc Compiler
Module 5 ● Vocabulary 1 a sensing block which will ask whatever question is typed into the block and display an input text box at the bottom.
Functions, Part 2 of 3 Topics Functions That Return a Value
Functions, Part 2 of 42 Topics Functions That Return a Value
Functions, Part 2 of 3 Topics Functions That Return a Value
Presentation transcript:

Topic 3 – The General Form of a C Program

CISC 105 – Topic 3 The General Form of a C Program Now, all of the basic building blocks of a C program are available. So, how do all of these components fit together? What does a C program look like?

CISC 105 – Topic 3 The General Form of a C Program The first component of a C program are the preprocessor directives. After these directives, the main function is found. This first statement of the main function is the first statement that runs when the program is executed. Thus, the main function is the starting point of the program.

CISC 105 – Topic 3 The General Form of a C Program After the function header, the main function starts with an open curly brace, “{“. Whatever is inside that brace is the main function. It ends with a closed curly brace, “}”. Inside the main function, variables are first declared. After the variable declarations, executable statements are found.

CISC 105 – Topic 3 The General Form of a C Program Thus, a C program follows the form: Preprocessor directives Main function header { variable declarations executable statements }

CISC 105 – Topic 3 Function Headers A function header is composed of a return type, the function name, an open paren “(“, an input parameter list, and a close paren “)”. The return type is the data type that is returned by the function. For the main function, the return type should always be an integer ( int ).

CISC 105 – Topic 3 Function Headers After the return type appears the name, in this case, main. In between the parentheses is the parameter list, which specifies the data that you will pass into the function. For the main function, this parameter list is blank (for now).

CISC 105 – Topic 3 The Composition of a Function After the function header, the function body is contained within the curly braces. After the variables declarations are the executable statements. The function body must end with a return function call. This returns control to the caller of the function.

CISC 105 – Topic 3 The return Function Call The return function is called with one parameter, of the data type specified in the function header as the return type. For the main function, as the return type must be an integer, an integer must be passed to the return function call at the end of the main function body. The return value of the main function gets returned to the operating system. A return value of 0 (zero) indicates successful program completion.

CISC 105 – Topic 3 The main Function Header Thus, a general C program looks like: Preprocessor directives int main() { variable declarations executable statements return(0); }

CISC 105 – Topic 3 Review (Problem #1) Write a complete C program that asks the user for a floating-point number, multiplies the number by 4 * PI (with PI set to in a constant macro) and the outputs the result. #include #define PI int main() { float number, answer; printf(“Number?”); scanf(“%f”,&number); answer = number * 4 * PI; printf(“The answer is:%f\n”,answer); return (0); }

CISC 105 – Topic 3 Review (Problem #2) Write a complete C program that asks for the radius of a circle and outputs the area and circumference of the circle.