Computer Programming & Problem Solving ( CPPS ) Turbo C Programming For The PC (Revised Edition ) By Robert Lafore

Size: px
Start display at page:

Download "Computer Programming & Problem Solving ( CPPS ) Turbo C Programming For The PC (Revised Edition ) By Robert Lafore"

Transcription

1 Sir Syed University of Engineering and Technology. Computer ming & Problem Solving ( CPPS ) Functions Chapter No 1 Compiled By: Sir Syed University of Engineering & Technology Computer Engineering Department University Road, Karachi-75300, PAKISTAN Muzammil Ahmad Khan Muhammad Kashif Shaikh Course Books Text Book: Turbo C ming For The PC (Revised Edition ) By Robert Lafore Reference Books: 1. Let Us C By Yashavant Kanetkar 2. C By Dissection ( Second Edition ) By Al Kelly & Ira Pohl 2 1

2 Course Website 3 Marks Distribution Assignments + Quiz 10 Mid Term 20 Lab Work 20 Semester Final Paper 50 Total Marks

3 Functions - Contents Functions Returning a value from a function Sending values to a function Arguments External Variables Preprocessor Directives 5 Functions We have already come across the functions main, printf and scanf. When you write a program of any size you will find that you can use functions to make life a whole lot easier. What we would like to do is write the checking code once and then use it at each point in the program. To do this you need to define a function to do the work for you. Functions are identified by name and can return a single value. We need to tell the compiler the name of our function, what parameters it has, and the type of information it returns. 6 3

4 What do Functions Do? Avoiding Unnecessary Repetition of Code Probably the original reason functions were invented was to avoid having to write the same code over and over. Organization If the operation of a program could be divided into separate activities, and each activity placed in a separate subroutine, then each subroutine could be written and checked out more or less independently. Separating the code into modular functions also made programs easier to design and understand. 7 What do Functions Do? Independence There is an advantage in making subroutines as independent from the main program and from one another as possible. For instance, subroutines were invented that had their own "private" variables; that is variables that could not be accessed from the main program or the other subroutine.this meant that a programmer did not need to worry about accidentally using the same variable names in different subroutines; the variables in each subroutine were protected from inadvertent tampering by other subroutines. 8 4

5 Simple Function Using a function is in some way like hiring someone to perform a specific job for you. Sometimes the interaction with such a person is very simple; sometimes it is more complex 9 /* Implementation of simple function */ void name (void) ; void main (void) clrscr( ); name( ) ; getch( ); 10 5

6 void name (void) int count; for ( count = 1 ; count < = 5 ; count + + ) printf ( SSUET ) ; printf ( \n ) ; 11 Structure of Functions Main ( ) is a function, so it is not surprising that name ( ), which is also a function, looks like it. The only thing special about main ( ) is that it is always executed first. It does not even matter if main ( ) is the first function in the listing, you can place other functions before it and main ( ) will still be executed first. In this example, main ( ) calls the function name ( ). Calls means to cause to be executed To prints the statement 10 times, main calls name ( ) twice. 12 6

7 Structure of Functions There are three program elements involved in using a function: 1. Function definition, 2. Call to the function, and 3. Function prototype 13 Function Definition The function itself is referred to as the function definition. The definition starts with a line that includes the function name, among other elements: i.e void name ( void ) This line is the declarator. The first void, means that name ( ) does not return anything, and the second means that it takes no arguments. 14 7

8 Function Definition Note that the declarator does not end with a semicolon. It is not a program statement, whose execution causes something to happen. Rather, it tells the compiler that a function is being defined. The function definition continues with the body of the functions enclosed in the braces. 15 Calling the Function As with the C library C functions we have seen such as printf ( ) and getch ( ), our user-written function name ( ) is called from the main ( ) simply by using its function name, including the parentheses following the name. The parentheses lets the compiler know that you are referring to a function and not to a variable or some thing else. Calling a function like this is a C language statement, so it ends with a semicolon. name ( ) ; 16 8

9 Sir Syed University of Engineering and Technology. Calling the Function This function call causes control to be transferred to the code in the definition of the name ( ). This function execute the written statements in the function, and then returns to the main ( ), to the statement immediately following the function call. 17 Function Prototype ( Declaration ) This is the third function related to the function example. This is the line before the beginning of the main ( ). void name ( void ) ; This looks very much like the declarator line at the start of the function definition, except that it ends with a semicolon. What is its purpose? 18 9

10 Function Prototype ( Declaration ) All the variables are defined by name and data type before they are used. A function is declared in a similar way at the beginning of a program before it is called. The function declaration or (prototype) tells the compiler the name of the function, the data type of the function returns (if any), and the number and the number and data types of the function s arguments (if any). 19 Function Prototype ( Declaration ) In the above example, the function returns nothing and takes no arguments; hence the two voids. The prototype is written before the main ( ) function, This causes the prototype to be visible to all the functions in a file

11 Function Prototype ( Declaration ) The key thing to remember about the prototype is that the data type of the return value must agree with that of the declarator in the function definition, and the number of arguments and their data types must agree with those in the function definition. In the above example, both the return value and the arguments are void. 21 Summary A prototype declares a function. A function call executes a function. A function definition is the function itself

12 Local Variables The variable count used in the function is known only to name ( ) ; it is invisible to the main ( ) function. If we added this statement to main ( ) (without declaring a variable count there ): printf ( %d, count ) ;we would get a compiler error because main ( ) would not know anything about this variable. We could declare another variable, also called count, in the main ( ) function; it would be a completely separate variable, known to main ( ) but not to name ( ). 23 Local Variables A local variable will be visible to the function it is defined in, but not to others. A local variable used in this way in a function is known in C as an automatic variable, because it is automatically created when a function is called and destroyed when the function returns. The length of time of a variable lasts is called its lifetime

13 A Sound Example This program uses the special character \x7, which is called BELL in the standard ASCII code. On the PC, printing this character, instead of ringing a bell, causes a beeping sound. 25 void beep (void) ; void main (void) beep ( ) ; void beep (void) long count ; printf ( \ x 7 ) ; delay ( ) ; printf ( \ x 7 ) ; 26 13

14 Delay Function The delay function suspends execution for interval (milliseconds). With a call to delay, the current program is suspended from execution for the time specified by the argument milliseconds. Declaration: void delay ( unsigned milliseconds ) ; 27 Function that returns a value A function that uses no arguments but returns a value performs a similar role. You call the function; it gets a certain piece of information and returns it to you. The function getche ( ) operates in just this way; you call it without giving it any information and it returns the value of the first character typed on the keyboard. Suppose we wanted a function that returned a character as getche ( ) does, but that also automatically translated any uppercase characters into lowercase 28 14

15 /* Implementation of lower case character using function */ char getlc (void) ; void main (void) char chlc; printf ( Type a for the selection, b for the second: ) ; chlc = getlc ( ) ; 29 switch ( chlc ) case a : printf ( \n You typed an a. ) ; break; case b : printf ( \n You typed a b. ) ; break; default : printf ( \n Non-existent selection. ) ; getch ( ); 30 15

16 char getlc (void) char ch; ch = getche ( ) ; if ( ch > 64 && ch < 91 ) ch = ch + 32 ; return ( ch ) ; 31 Output: Type a for the selection, b for the second: a You typed an a. Type a for the selection, b for the second: A You typed an a. Type a for the selection, b for the second: c You chose a non-existent selection

17 Note Our new function, getlc ( ), returns a value of type char. The return type is no longer void as in the previous examples. Notice that both the prototype and the declarator in the function definition begins with char to reflect this fact. Just as in the case of getche ( ), the function itself appears to take on the value it is returning. It can thus be used as if it were a variable in an assignment statement, and the value returned ( a lower case character ) will be assigned to the variable, chlc which is then used in the switch statement to determine which message will be printed. Notice how the capital A typed by the user is successfully converted to the lowercase. 33 Return Statement The return ( ) statement has 2 purposes. First, executing it immediately transfer control from the function back to the calling program, and Second whatever is inside the parentheses following return is returned as a value to the calling program. The return ( ) statement need not to be at the end of the function. It can occur anywhere in the function; as soon as it is encountered, control will return to the calling program

18 Return Statement Example char getlc (void) char ch; ch = getche ( ) ; if ( ch > 64 && ch < 91 ) return ( ch + 32 ) ; else return ( ch ) ; 35 Returning Type int The return statement can also be used without the parenthesis. When this is the case, no value is returned to the calling program. Return statement can also return a value of type int i.e integer. Here is the example in which function getmins ( ), gets a time in hours and minutes from the user. The main program uses this function to calculate the difference in seconds between two times

19 int getmins (void) ; void main (void) int mins1, min2 ; printf ( Type first time ( from 10 : 15 ) : ) ; mins1 = getmins ( ) ; printf ( Type second time ( later 11 : 30 ) : ) ; mins1 = getmins ( ) ; printf ( Difference is %d minutes., mins2 mins1 ) ; getch ( ); 37 int getmins (void) int hours, minutes ; scanf ( %d : %d, &hours, &minutes ) ; return ( hours * 60 + minutes ) ; 38 19

20 Output: Type first time ( from 10 : 15 ) : 6 : 00 Type second time ( later 11 : 30 ) : 7 : 45 Difference is 105 minutes. 39 Returning Type Float Here is the example in which a function returns type float. In this program, the main ( ) function asks the user for the radius of a sphere, and then calls a function named area ( ) to calculate the area of the sphere. The area ( ) function returns the area of the sphere in the form of a floating point value

21 float area (float) ; void main (void) float radius ; printf ( Enter radius of a sphere : ) ; scanf ( %f, &radius ) ; printf ( Area of a sphere is %.2f, area (radius) ) ; getch ( ); 41 float area (float rad) return ( 4 * 3.14 * rad * rad ) ; Output: Enter radius of a sphere : 10 Area of a sphere is

22 Limitation of return ( ) statement mer should be aware of a key limitation in the use of the return ( ) statement: you can only use it to return one value by a function. 43 Using Argument to pass data to a Function The mechanism used to convey information to a function is the argument. You have already used arguments in printf ( ) and scanf ( ) functions; the format strings and the values used inside the parentheses in these function are arguments

23 /* Draws Bar-graph and Implementation of Function Arguments */ void bar ( int ) ; void main (void) printf ( Ali \t ) ; bar (10) ; printf ( Babar \t ); bar (15) ; printf ( Faraz \t ) ; bar (20) ; getch ( ); 45 void bar (int score) int count ; for ( count =1 ; count < = score ; count ++ ) printf ( \xcd ) ; printf ( \n ) ; 46 23

24 Output: Ali ========== Babar =============== Faraz ==================== This program generates a bar graph of names and bars representing, say the score in a spelling test. In this program the purpose of the function bar ( ) is to draw a horizontal line, made of the double line graphics character ( \xcd ) on the screen. 47 Structure of a Function Call with Arguments bar (27) ; In the function definition, a variable name score is placed in the parentheses following bar : void bar ( int score ) This ensures that the value included between parentheses in the main program is assigned to the variable between parentheses in the function definition. Notice that the data type of the score is also specified, in the function definition. This constitutes a definition of the argument variable, setting aside memory space for it in the function

25 Passing Variables as Arguments In the above example we passed constants (such as the number 27) as an argument to the function bar ( ). We can also use a variable in the calling program as this variation on the program discusses above of the bar graph. 49 void bar ( int inscore ) ; void main (void) int inscore = 1 ; while ( inscore! = 0 ) printf ( Score = ) ; scanf ( %d, &inscore ) ; bar ( inscore ) ; /* Actual Arguments */ 50 25

26 void bar (int score) /* Formal Arguments */ int count ; for ( count =1 ; count < = score ; count ++ ) printf ( \xcd ) ; printf ( \n ) ; 51 Output Score = 20 ==================== Score = 10 ========== Score = 25 ============================ 52 26

27 Note Different names have been assigned to the arguments in the calling and called functions; inscore in the calling program and score in the function. Actually, we could have used the same name for both variables; since they are in different functions, the compiler would still consider them to be separate variables. 53 Note The argument in the calling program is referred to as the Actual Argument, while the argument in the called function is the Formal Argument. In this case, the variable inscore in the calling program is the actual argument, and the variable score in the function is the formal argument

28 Sir Syed University of Engineering and Technology. Using More than One Function You can use as many functions as you like in a program, and any of the functions can call any of the other functions. In C Language, all functions including main ( ) have equal status and are visible to all other functions. 55 /* Implementation of Multi Functions */ int sqr ( int ) ; int sum ( int, int ) ; int sumsqr ( int, int ) ; void main (void) int num1, num2 ; printf ( Type 2 numbers: ) ; scanf ( %d %d, &num1, &num2 ) ; printf ( Sum of the squares is %d, sumsqr ( num1,num2) ) ; 56 28

29 void sumsqr ( int j, int k ) return ( sum ( sqr ( j ), sqr ( k ) ) ) ; void sqr ( int z ) return ( z * z ) ; 57 void sum ( int x, int y ) return ( x + y ) ; 58 29

30 External Variables While local variables are preferred for most purposes, it is sometimes desirable to use a variable known to all the functions in a program rather than just one. This is true when many different functions must read or modify a variable, making it clumsy or impractical to communicate the value of the variable from function to function using arguments and return values. In this case, we use an External Variables (sometimes called a global variable). 59 /* Implementation of External Variables */ void oddeven ( void ) ; /* Function Prototype */ void negative ( void ) ; int keynum; /* External Variables */ void main (void) printf ( Type Keynum: ) ; scanf ( %d, &keynum ) ; oddeven ( ); /* Function Call */ negative ( ); 60 30

31 void oddeven ( void ) if ( keynum % 2 ) printf ( Keynum is Odd. \n ) ; else printf ( Keynum is Even. \n ) ; 61 void negative ( void ) if ( keynum < 0 ) printf ( Keynum is Negative. \n ) ; else printf ( Keynum is Positive. \n ) ; 62 31

32 Output: Type Keynum: - 25 Keynum is Odd. Keynum is Negative. Type Keynum: 50 Keynum is Even. Keynum is Positive. 63 Note There are several reasons why external variables are not good idea. First, external variables are not protected from accidental alteration by functions that have no business modifying them. Second, external variable use memory less efficiently than the local variables. The rule is that variables should be local unless there is a very good reason to make them external

33 Preprocessor Directives Preprocessor directives on the other hand, are instructions to the compiler itself. Rather than being translated into machine language, they are operated on directly by the compiler before the computation process even begins; hence it named preprocessor. 65 Preprocessor Directives Normal program statements are instructions to the microprocessor; Preprocessor directives are instructions to the compiler. Preprocessor directives always start with a number sign ( # ). The directives can be placed anywhere in a program, but are often used at the beginning of a file, before main ( ), or before the beginning of particular functions

34 Sir Syed University of Engineering and Technology. The # define Directive /* Implementation of define directive */ # define P I float area ( float ) ; /* Function Prototype */ void main (void) float radius ; printf ( Enter radius of the sphere: ) ; scanf ( %f, &radius ) ; printf ( Area of the sphere is %.2f, area (radius) ); 67 The # define Directive float area ( float rad ) return ( 4 * P I * rad * rad ) ; 68 34

35 The # define Directive The preprocessor first looks for all program lines beginning with the number sign ( # ). When it sees the # define directive, it goes through the entire program, and at every place it finds PI it substitutes the phrase It is very much like a word processor s global search and replace. 69 The # define Directive The phrase on the left ( P I ), which will be searched for it, is called the identifier. The phrase on the right ( ), which will be substituted for it, is called the text. A space separates the identifier from the text. By convention, the identifier is written in all caps. This makes it easy when looking at the listing to tell which part of the program will be altered by # define directives

36 Why use # define? With the help of the # define directive, we have made our program easier to read. Ordinarily, you would need to go through the program and manually change each occurrence of the constant. However, if you have defined to be PI in a # define directive, you only need to make one changer, in the # define directive itself: 71 Why not use variable names? A variable could also provide a meaningful name for a constant, and permit one change to effect many occurrence of the constant. It is true, a variable can be used in this way

37 Why not use variable names? However, there are at least three reasons why it is bad idea. First, it is inefficient, since the compiler can generate faster and more compact code for constants than it can for the variables. Second, using a more compact code for constants encourages sloppy thinking and makes program more difficult to understand it. Third, there is always the danger that a variable will be altered inadvertently during the execution o the program so that it is no longer the constant you think it is. 73 The const Modifier The new ANSI standard C defines a modifier, const that can be used to achieve almost the same effect as # define when creating constants. For example const float PI = ; This const tells the compiler not to permit any changes to the variable, so if you try to modify PI you will get an error message from the compiler

38 Macros The additional power comes from # define is the ability to use arguments. A # define directive can take arguments, much as a function does. A Macro generates more code but executes more quickly than a functions. 75 Macros # define WRITE printf ( SSUET ); void main (void) printf ( CPPS-1 ) ; WRITE getch ( ); 76 38

39 Macros # define PR ( n ) printf ( %.2f \n, n ) ; /* macro definition */ void main (void) float num1 = ; float num2 ; num2 = 5.0 / 2.5 ; PR ( num1 ) ; PR ( num2 ) ; CPPS - Chapter No1 : Functions 77 Macros # define SUM ( x, y ) x + y /* macro definition */ answer = 10 * SUM( 1, 2 ) 78 39

40 The # include Directive The # include directive causes one source file to be included in another. instead of having to rewrite all the macro every time you wrote a program that used them, you could insert them into the.cpp source file using the # include directive 79 /* Implementation of the # include directive */ # include<stdio.h> # include<conio.h> # include " c:\ tc\bin\ my.h " void main ( void ) int a, b, ans = 0 ; printf ( " Enter any two numbers: \n " ) ; scanf ( " %d %d ", &a, &b ) ; mul ( a, b ) ; 80 40

41 /* Implementation header file my.h */ void mul ( int, int ) ; void mul ( int aa, int bb ) int ans ; ans = aa * bb ; printf ( " Answer = %d ", ans ) ; 81 The # include Directive There are actually 2 ways to write # include statements. The variation in format tells the preprocessor where to look for the file you want included. The variation shown above # include my.h shows the file name surrounded by quotes. This causes the preprocessor to start searching for the file in the directory containing the current source file. The other approach is to use angle brackets # include <stdio.h>. This format causes the preprocessor to start searching in the standard header directory

42 Standard Header Files Another reason to use the header files is to provide prototype of library functions. Each library function provided with Turbo C is associated with a header file: that is, a file with the extension.h that is kept in the \ INCLUDE directory. The prototype for the function is part of the corresponding header file. 83 Class Assignment No Differentiate between function definition and function declaration. 2. Write a program to calculate the factorial of a input number using a user defined function. 3. What is the purpose of Macro in C language. 4. Write a program that implements a macro. 5. Write a program that implements a user defined header file

Sir Syed University of Engineering and Technology. Computer Programming & Problem Solving ( CPPS )

Sir Syed University of Engineering and Technology. Computer Programming & Problem Solving ( CPPS ) Computer Programming & Problem Solving ( CPPS ) Chapter No 2 Sir Syed University of Engineering & Technology Computer Engineering Department University Road, Karachi-75300, PAKISTAN Muzammil Ahmad Khan

More information

Computer Programming & Problem Solving ( CPPS )

Computer Programming & Problem Solving ( CPPS ) Computer Programming & Problem Solving ( CPPS ) Chapter No 3 Sir Syed University of Engineering & Technology Computer Engineering Department University Road, Karachi-75300, PAKISTAN Muzammil Ahmad Khan

More information

Sir Syed University of Engineering and Technology. Computer Programming & Problem Solving ( CPPS ) Pointers. Chapter No 7

Sir Syed University of Engineering and Technology. Computer Programming & Problem Solving ( CPPS ) Pointers. Chapter No 7 Computer Programming & Problem Solving ( CPPS ) Chapter No 7 Sir Syed University of Engineering & Technology Computer Engineering Department University Road, Karachi-75300, PAKISTAN Muzammil Ahmad Khan

More information

A Fast Review of C Essentials Part I

A Fast Review of C Essentials Part I A Fast Review of C Essentials Part I Structural Programming by Z. Cihan TAYSI Outline Program development C Essentials Functions Variables & constants Names Formatting Comments Preprocessor Data types

More information

Tutorial No. 2 - Solution (Overview of C)

Tutorial No. 2 - Solution (Overview of C) Tutorial No. 2 - Solution (Overview of C) Computer Programming and Utilization (2110003) 1. Explain the C program development life cycle using flowchart in detail. OR Explain the process of compiling and

More information

BLM2031 Structured Programming. Zeyneb KURT

BLM2031 Structured Programming. Zeyneb KURT BLM2031 Structured Programming Zeyneb KURT 1 Contact Contact info office : D-219 e-mail zeynebkurt@gmail.com, zeyneb@ce.yildiz.edu.tr When to contact e-mail first, take an appointment What to expect help

More information

Unit 4 Preprocessor Directives

Unit 4 Preprocessor Directives 1 What is pre-processor? The job of C preprocessor is to process the source code before it is passed to the compiler. Source Code (test.c) Pre-Processor Intermediate Code (test.i) Compiler The pre-processor

More information

C: How to Program. Week /Mar/05

C: How to Program. Week /Mar/05 1 C: How to Program Week 2 2007/Mar/05 Chapter 2 - Introduction to C Programming 2 Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers

More information

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language 1 History C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell Labs. C was originally first implemented on the DEC

More information

Presented By : Gaurav Juneja

Presented By : Gaurav Juneja Presented By : Gaurav Juneja Introduction C is a general purpose language which is very closely associated with UNIX for which it was developed in Bell Laboratories. Most of the programs of UNIX are written

More information

AN OVERVIEW OF C, PART 3. CSE 130: Introduction to Programming in C Stony Brook University

AN OVERVIEW OF C, PART 3. CSE 130: Introduction to Programming in C Stony Brook University AN OVERVIEW OF C, PART 3 CSE 130: Introduction to Programming in C Stony Brook University FANCIER OUTPUT FORMATTING Recall that you can insert a text field width value into a printf() format specifier:

More information

Chapter 2 - Introduction to C Programming

Chapter 2 - Introduction to C Programming Chapter 2 - Introduction to C Programming 2 Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers 2.4 Memory Concepts 2.5 Arithmetic

More information

Unit 7. Functions. Need of User Defined Functions

Unit 7. Functions. Need of User Defined Functions Unit 7 Functions Functions are the building blocks where every program activity occurs. They are self contained program segments that carry out some specific, well defined task. Every C program must have

More information

Preprocessor Directives

Preprocessor Directives C++ By 6 EXAMPLE Preprocessor Directives As you might recall from Chapter 2, What Is a Program?, the C++ compiler routes your programs through a preprocessor before it compiles them. The preprocessor can

More information

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath UNIT - I Introduction to C Programming Introduction to C C was originally developed in the year 1970s by Dennis Ritchie at Bell Laboratories, Inc. C is a general-purpose programming language. It has been

More information

Technical Questions. Q 1) What are the key features in C programming language?

Technical Questions. Q 1) What are the key features in C programming language? Technical Questions Q 1) What are the key features in C programming language? Portability Platform independent language. Modularity Possibility to break down large programs into small modules. Flexibility

More information

Lecture 05 I/O statements Printf, Scanf Simple statements, Compound statements

Lecture 05 I/O statements Printf, Scanf Simple statements, Compound statements Programming, Data Structures and Algorithms Prof. Shankar Balachandran Department of Computer Science and Engineering Indian Institute of Technology, Madras Lecture 05 I/O statements Printf, Scanf Simple

More information

C Language Programming

C Language Programming Experiment 2 C Language Programming During the infancy years of microprocessor based systems, programs were developed using assemblers and fused into the EPROMs. There used to be no mechanism to find what

More information

UNIT 3 FUNCTIONS AND ARRAYS

UNIT 3 FUNCTIONS AND ARRAYS UNIT 3 FUNCTIONS AND ARRAYS Functions Function definitions and Prototypes Calling Functions Accessing functions Passing arguments to a function - Storage Classes Scope rules Arrays Defining an array processing

More information

UIC. C Programming Primer. Bharathidasan University

UIC. C Programming Primer. Bharathidasan University C Programming Primer UIC C Programming Primer Bharathidasan University Contents Getting Started 02 Basic Concepts. 02 Variables, Data types and Constants...03 Control Statements and Loops 05 Expressions

More information

Chapter 1 & 2 Introduction to C Language

Chapter 1 & 2 Introduction to C Language 1 Chapter 1 & 2 Introduction to C Language Copyright 2007 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 1 & 2 - Introduction to C Language 2 Outline 1.1 The History

More information

Data Types and Variables in C language

Data Types and Variables in C language Data Types and Variables in C language Basic structure of C programming To write a C program, we first create functions and then put them together. A C program may contain one or more sections. They are

More information

Functions. Prof. Indranil Sen Gupta. Dept. of Computer Science & Engg. Indian Institute t of Technology Kharagpur. Introduction

Functions. Prof. Indranil Sen Gupta. Dept. of Computer Science & Engg. Indian Institute t of Technology Kharagpur. Introduction Functions Prof. Indranil Sen Gupta Dept. of Computer Science & Engg. Indian Institute t of Technology Kharagpur Programming and Data Structure 1 Function Introduction A self-contained program segment that

More information

Lecture 2: C Programming Basic

Lecture 2: C Programming Basic ECE342 Introduction to Embedded Systems Lecture 2: C Programming Basic Ying Tang Electrical and Computer Engineering Rowan University 1 Facts about C C was developed in 1972 in order to write the UNIX

More information

INTRODUCTION 1 AND REVIEW

INTRODUCTION 1 AND REVIEW INTRODUTION 1 AND REVIEW hapter SYS-ED/ OMPUTER EDUATION TEHNIQUES, IN. Programming: Advanced Objectives You will learn: Program structure. Program statements. Datatypes. Pointers. Arrays. Structures.

More information

Fundamentals of Programming Session 4

Fundamentals of Programming Session 4 Fundamentals of Programming Session 4 Instructor: Reza Entezari-Maleki Email: entezari@ce.sharif.edu 1 Fall 2011 These slides are created using Deitel s slides, ( 1992-2010 by Pearson Education, Inc).

More information

Rule 1-3: Use white space to break a function into paragraphs. Rule 1-5: Avoid very long statements. Use multiple shorter statements instead.

Rule 1-3: Use white space to break a function into paragraphs. Rule 1-5: Avoid very long statements. Use multiple shorter statements instead. Chapter 9: Rules Chapter 1:Style and Program Organization Rule 1-1: Organize programs for readability, just as you would expect an author to organize a book. Rule 1-2: Divide each module up into a public

More information

Programming and Data Structure

Programming and Data Structure Programming and Data Structure Sujoy Ghose Sudeshna Sarkar Jayanta Mukhopadhyay Dept. of Computer Science & Engineering. Indian Institute of Technology Kharagpur Spring Semester 2012 Programming and Data

More information

printf( Please enter another number: ); scanf( %d, &num2);

printf( Please enter another number: ); scanf( %d, &num2); CIT 593 Intro to Computer Systems Lecture #13 (11/1/12) Now that we've looked at how an assembly language program runs on a computer, we're ready to move up a level and start working with more powerful

More information

Preview from Notesale.co.uk Page 6 of 52

Preview from Notesale.co.uk Page 6 of 52 Binary System: The information, which it is stored or manipulated by the computer memory it will be done in binary mode. RAM: This is also called as real memory, physical memory or simply memory. In order

More information

Basic Elements of C. Staff Incharge: S.Sasirekha

Basic Elements of C. Staff Incharge: S.Sasirekha Basic Elements of C Staff Incharge: S.Sasirekha Basic Elements of C Character Set Identifiers & Keywords Constants Variables Data Types Declaration Expressions & Statements C Character Set Letters Uppercase

More information

Introduction to C Programming. Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan

Introduction to C Programming. Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan Introduction to C Programming Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan Outline Printing texts Adding 2 integers Comparing 2 integers C.E.,

More information

Computer Science & Information Technology (CS) Rank under AIR 100. Examination Oriented Theory, Practice Set Key concepts, Analysis & Summary

Computer Science & Information Technology (CS) Rank under AIR 100. Examination Oriented Theory, Practice Set Key concepts, Analysis & Summary GATE- 2016-17 Postal Correspondence 1 C-Programming Computer Science & Information Technology (CS) 20 Rank under AIR 100 Postal Correspondence Examination Oriented Theory, Practice Set Key concepts, Analysis

More information

CHAPTER 4 FUNCTIONS. 4.1 Introduction

CHAPTER 4 FUNCTIONS. 4.1 Introduction CHAPTER 4 FUNCTIONS 4.1 Introduction Functions are the building blocks of C++ programs. Functions are also the executable segments in a program. The starting point for the execution of a program is main

More information

Creating a C++ Program

Creating a C++ Program Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer. 1 Creating a C++ Program created using an

More information

LESSON 4. The DATA TYPE char

LESSON 4. The DATA TYPE char LESSON 4 This lesson introduces some of the basic ideas involved in character processing. The lesson discusses how characters are stored and manipulated by the C language, how characters can be treated

More information

There are algorithms, however, that need to execute statements in some other kind of ordering depending on certain conditions.

There are algorithms, however, that need to execute statements in some other kind of ordering depending on certain conditions. Introduction In the programs that we have dealt with so far, all statements inside the main function were executed in sequence as they appeared, one after the other. This type of sequencing is adequate

More information

Subject: Fundamental of Computer Programming 2068

Subject: Fundamental of Computer Programming 2068 Subject: Fundamental of Computer Programming 2068 1 Write an algorithm and flowchart to determine whether a given integer is odd or even and explain it. Algorithm Step 1: Start Step 2: Read a Step 3: Find

More information

Have examined process Creating program Have developed program Written in C Source code

Have examined process Creating program Have developed program Written in C Source code Preprocessing, Compiling, Assembling, and Linking Introduction In this lesson will examine Architecture of C program Introduce C preprocessor and preprocessor directives How to use preprocessor s directives

More information

ADARSH VIDYA KENDRA NAGERCOIL COMPUTER SCIENCE. Grade: IX C++ PROGRAMMING. Department of Computer Science 1

ADARSH VIDYA KENDRA NAGERCOIL COMPUTER SCIENCE. Grade: IX C++ PROGRAMMING. Department of Computer Science 1 NAGERCOIL COMPUTER SCIENCE Grade: IX C++ PROGRAMMING 1 C++ 1. Object Oriented Programming OOP is Object Oriented Programming. It was developed to overcome the flaws of the procedural approach to programming.

More information

UNIT- 3 Introduction to C++

UNIT- 3 Introduction to C++ UNIT- 3 Introduction to C++ C++ Character Sets: Letters A-Z, a-z Digits 0-9 Special Symbols Space + - * / ^ \ ( ) [ ] =!= . $, ; : %! &? _ # = @ White Spaces Blank spaces, horizontal tab, carriage

More information

Introduction. C provides two styles of flow control:

Introduction. C provides two styles of flow control: Introduction C provides two styles of flow control: Branching Looping Branching is deciding what actions to take and looping is deciding how many times to take a certain action. Branching constructs: if

More information

CS6202 - PROGRAMMING & DATA STRUCTURES UNIT I Part - A 1. W hat are Keywords? Keywords are certain reserved words that have standard and pre-defined meaning in C. These keywords can be used only for their

More information

Problem Solving through Programming In C Prof. Anupam Basu Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur

Problem Solving through Programming In C Prof. Anupam Basu Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur Problem Solving through Programming In C Prof. Anupam Basu Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur Lecture 18 Switch Statement (Contd.) And Introduction to

More information

Programming for Engineers Introduction to C

Programming for Engineers Introduction to C Programming for Engineers Introduction to C ICEN 200 Spring 2018 Prof. Dola Saha 1 Simple Program 2 Comments // Fig. 2.1: fig02_01.c // A first program in C begin with //, indicating that these two lines

More information

Introduction to C programming. By Avani M. Sakhapara Asst Professor, IT Dept, KJSCE

Introduction to C programming. By Avani M. Sakhapara Asst Professor, IT Dept, KJSCE Introduction to C programming By Avani M. Sakhapara Asst Professor, IT Dept, KJSCE Classification of Software Computer Software System Software Application Software Growth of Programming Languages History

More information

CS113: Lecture 4. Topics: Functions. Function Activation Records

CS113: Lecture 4. Topics: Functions. Function Activation Records CS113: Lecture 4 Topics: Functions Function Activation Records 1 Why functions? Functions add no expressive power to the C language in a formal sense. Why have them? Breaking tasks into smaller ones make

More information

Unit 3 Decision making, Looping and Arrays

Unit 3 Decision making, Looping and Arrays Unit 3 Decision making, Looping and Arrays Decision Making During programming, we have a number of situations where we may have to change the order of execution of statements based on certain conditions.

More information

Functions. Functions are everywhere in C. Pallab Dasgupta Professor, Dept. of Computer Sc & Engg INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR

Functions. Functions are everywhere in C. Pallab Dasgupta Professor, Dept. of Computer Sc & Engg INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR 1 Functions Functions are everywhere in C Pallab Dasgupta Professor, Dept. of Computer Sc & Engg INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR Introduction Function A self-contained program segment that carries

More information

Chapter 5 C Functions

Chapter 5 C Functions Chapter 5 C Functions Objectives of this chapter: To construct programs from small pieces called functions. Common math functions in math.h the C Standard Library. sin( ), cos( ), tan( ), atan( ), sqrt(

More information

Module 10A Lecture - 20 What is a function? Why use functions Example: power (base, n)

Module 10A Lecture - 20 What is a function? Why use functions Example: power (base, n) Programming, Data Structures and Algorithms Prof. Shankar Balachandran Department of Computer Science and Engineering Indian Institute of Technology, Madras Module 10A Lecture - 20 What is a function?

More information

2. Numbers In, Numbers Out

2. Numbers In, Numbers Out COMP1917: Computing 1 2. Numbers In, Numbers Out Reading: Moffat, Chapter 2. COMP1917 15s2 2. Numbers In, Numbers Out 1 The Art of Programming Think about the problem Write down a proposed solution Break

More information

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #54. Organizing Code in multiple files

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #54. Organizing Code in multiple files Introduction to Programming in C Department of Computer Science and Engineering Lecture No. #54 Organizing Code in multiple files (Refer Slide Time: 00:09) In this lecture, let us look at one particular

More information

Laboratory 2: Programming Basics and Variables. Lecture notes: 1. A quick review of hello_comment.c 2. Some useful information

Laboratory 2: Programming Basics and Variables. Lecture notes: 1. A quick review of hello_comment.c 2. Some useful information Laboratory 2: Programming Basics and Variables Lecture notes: 1. A quick review of hello_comment.c 2. Some useful information 3. Comment: a. name your program with extension.c b. use o option to specify

More information

Unit. Programming Fundamentals. School of Science and Technology INTRODUCTION

Unit. Programming Fundamentals. School of Science and Technology INTRODUCTION INTRODUCTION Programming Fundamentals Unit 1 In order to communicate with each other, we use natural languages like Bengali, English, Hindi, Urdu, French, Gujarati etc. We have different language around

More information

It is necessary to have a single function main in every C program, along with other functions used/defined by the programmer.

It is necessary to have a single function main in every C program, along with other functions used/defined by the programmer. Functions A number of statements grouped into a single logical unit are called a function. The use of function makes programming easier since repeated statements can be grouped into functions. Splitting

More information

Fundamental Data Types. CSE 130: Introduction to Programming in C Stony Brook University

Fundamental Data Types. CSE 130: Introduction to Programming in C Stony Brook University Fundamental Data Types CSE 130: Introduction to Programming in C Stony Brook University Program Organization in C The C System C consists of several parts: The C language The preprocessor The compiler

More information

Fundamental of Programming (C)

Fundamental of Programming (C) Borrowed from lecturer notes by Omid Jafarinezhad Fundamental of Programming (C) Lecturer: Vahid Khodabakhshi Lecture 3 Constants, Variables, Data Types, And Operations Department of Computer Engineering

More information

Intro to Computer Programming (ICP) Rab Nawaz Jadoon

Intro to Computer Programming (ICP) Rab Nawaz Jadoon Intro to Computer Programming (ICP) Rab Nawaz Jadoon DCS COMSATS Institute of Information Technology Assistant Professor COMSATS IIT, Abbottabad Pakistan Introduction to Computer Programming (ICP) What

More information

Functions. (transfer of parameters, returned values, recursion, function pointers).

Functions. (transfer of parameters, returned values, recursion, function pointers). Functions (transfer of parameters, returned values, recursion, function pointers). A function is a named, independent section of C/C++ code that performs a specific task and optionally returns a value

More information

Fundamentals of Programming. Lecture 3: Introduction to C Programming

Fundamentals of Programming. Lecture 3: Introduction to C Programming Fundamentals of Programming Lecture 3: Introduction to C Programming Instructor: Fatemeh Zamani f_zamani@ce.sharif.edu Sharif University of Technology Computer Engineering Department Outline A Simple C

More information

3. Except for strings, double quotes, identifiers, and keywords, C++ ignores all white space.

3. Except for strings, double quotes, identifiers, and keywords, C++ ignores all white space. Chapter 2: Problem Solving Using C++ TRUE/FALSE 1. Modular programs are easier to develop, correct, and modify than programs constructed in some other manner. ANS: T PTS: 1 REF: 45 2. One important requirement

More information

CSc Introduction to Computing

CSc Introduction to Computing CSc 10200 Introduction to Computing Lecture 2 Edgardo Molina Fall 2011 - City College of New York Thursday, September 1, 2011 Introduction to C++ Modular program: A program consisting of interrelated segments

More information

Review. Modules. CS 151 Review #6. Sample Program 6.1a:

Review. Modules. CS 151 Review #6. Sample Program 6.1a: Review Modules A key element of structured (well organized and documented) programs is their modularity: the breaking of code into small units. These units, or modules, that do not return a value are called

More information

Computers Programming Course 7. Iulian Năstac

Computers Programming Course 7. Iulian Năstac Computers Programming Course 7 Iulian Năstac Recap from previous course Operators in C Programming languages typically support a set of operators, which differ in the calling of syntax and/or the argument

More information

Programming and Data Structures

Programming and Data Structures Programming and Data Structures Teacher: Sudeshna Sarkar sudeshna@cse.iitkgp.ernet.in Department of Computer Science and Engineering Indian Institute of Technology Kharagpur #include int main()

More information

MA 511: Computer Programming Lecture 2: Partha Sarathi Mandal

MA 511: Computer Programming Lecture 2: Partha Sarathi Mandal MA 511: Computer Programming Lecture 2: http://www.iitg.ernet.in/psm/indexing_ma511/y10/index.html Partha Sarathi Mandal psm@iitg.ernet.ac.in Dept. of Mathematics, IIT Guwahati Semester 1, 2010-11 Largest

More information

Functions. Lab 4. Introduction: A function : is a collection of statements that are grouped together to perform an operation.

Functions. Lab 4. Introduction: A function : is a collection of statements that are grouped together to perform an operation. Lab 4 Functions Introduction: A function : is a collection of statements that are grouped together to perform an operation. The following is its format: type name ( parameter1, parameter2,...) { statements

More information

2/29/2016. Definition: Computer Program. A simple model of the computer. Example: Computer Program. Data types, variables, constants

2/29/2016. Definition: Computer Program. A simple model of the computer. Example: Computer Program. Data types, variables, constants Data types, variables, constants Outline.1 Introduction. Text.3 Memory Concepts.4 Naming Convention of Variables.5 Arithmetic in C.6 Type Conversion Definition: Computer Program A Computer program is a

More information

Chapter 8: Function. In this chapter, you will learn about

Chapter 8: Function. In this chapter, you will learn about Principles of Programming Chapter 8: Function In this chapter, you will learn about Introduction to function User-defined function Formal and Actual Parameters Parameter passing by value Parameter passing

More information

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University Unit 1 Programming Language and Overview of C 1. State whether the following statements are true or false. a. Every line in a C program should end with a semicolon. b. In C language lowercase letters are

More information

Course Outline Introduction to C-Programming

Course Outline Introduction to C-Programming ECE3411 Fall 2015 Lecture 1a. Course Outline Introduction to C-Programming Marten van Dijk, Syed Kamran Haider Department of Electrical & Computer Engineering University of Connecticut Email: {vandijk,

More information

Superior University. Department of Electrical Engineering CS-115. Computing Fundamentals. Experiment No.1

Superior University. Department of Electrical Engineering CS-115. Computing Fundamentals. Experiment No.1 Superior University Department of Electrical Engineering CS-115 Computing Fundamentals Experiment No.1 Introduction of Compiler, Comments, Program Structure, Input Output, Data Types and Arithmetic Operators

More information

15 FUNCTIONS IN C 15.1 INTRODUCTION

15 FUNCTIONS IN C 15.1 INTRODUCTION 15 FUNCTIONS IN C 15.1 INTRODUCTION In the earlier lessons we have already seen that C supports the use of library functions, which are used to carry out a number of commonly used operations or calculations.

More information

2. Numbers In, Numbers Out

2. Numbers In, Numbers Out REGZ9280: Global Education Short Course - Engineering 2. Numbers In, Numbers Out Reading: Moffat, Chapter 2. REGZ9280 14s2 2. Numbers In, Numbers Out 1 The Art of Programming Think about the problem Write

More information

C++ PROGRAMMING BASICS

C++ PROGRAMMING BASICS C++ Notes 1 By V. D. Gokhale C++ PROGRAMMING BASICS Difference between C and C++ :- (1) When we invoke turbo C++ editor by c:\tc\tc [Enter]. The editor window shows the file name with.c extension. [noname00.c].

More information

ANSI C Programming Simple Programs

ANSI C Programming Simple Programs ANSI C Programming Simple Programs /* This program computes the distance between two points */ #include #include #include main() { /* Declare and initialize variables */ double

More information

Computers Programming Course 11. Iulian Năstac

Computers Programming Course 11. Iulian Năstac Computers Programming Course 11 Iulian Năstac Recap from previous course Cap. Matrices (Arrays) Matrix representation is a method used by a computer language to store matrices of different dimension in

More information

Functions BCA-105. Few Facts About Functions:

Functions BCA-105. Few Facts About Functions: Functions When programs become too large and complex and as a result the task of debugging, testing, and maintaining becomes difficult then C provides a most striking feature known as user defined function

More information

QUIZ. What is wrong with this code that uses default arguments?

QUIZ. What is wrong with this code that uses default arguments? QUIZ What is wrong with this code that uses default arguments? Solution The value of the default argument should be placed in either declaration or definition, not both! QUIZ What is wrong with this code

More information

PART I. Part II Answer to all the questions 1. What is meant by a token? Name the token available in C++.

PART I.   Part II Answer to all the questions 1. What is meant by a token? Name the token available in C++. Unit - III CHAPTER - 9 INTRODUCTION TO C++ Choose the correct answer. PART I 1. Who developed C++? (a) Charles Babbage (b) Bjarne Stroustrup (c) Bill Gates (d) Sundar Pichai 2. What was the original name

More information

Binghamton University. CS-211 Fall Syntax. What the Compiler needs to understand your program

Binghamton University. CS-211 Fall Syntax. What the Compiler needs to understand your program Syntax What the Compiler needs to understand your program 1 Pre-Processing Any line that starts with # is a pre-processor directive Pre-processor consumes that entire line Possibly replacing it with other

More information

LAB: INTRODUCTION TO FUNCTIONS IN C++

LAB: INTRODUCTION TO FUNCTIONS IN C++ LAB: INTRODUCTION TO FUNCTIONS IN C++ MODULE 2 JEFFREY A. STONE and TRICIA K. CLARK COPYRIGHT 2014 VERSION 4.0 PALMS MODULE 2 LAB: FUNCTIONS IN C++ 2 Introduction This lab will provide students with an

More information

GE U111 Engineering Problem Solving & Computation Lecture 6 February 2, 2004

GE U111 Engineering Problem Solving & Computation Lecture 6 February 2, 2004 GE U111 Engineering Problem Solving & Computation Lecture 6 February 2, 2004 Functions and Program Structure Today we will be learning about functions. You should already have an idea of their uses. Cout

More information

Functions. Autumn Semester 2009 Programming and Data Structure 1. Courtsey: University of Pittsburgh-CSD-Khalifa

Functions. Autumn Semester 2009 Programming and Data Structure 1. Courtsey: University of Pittsburgh-CSD-Khalifa Functions Autumn Semester 2009 Programming and Data Structure 1 Courtsey: University of Pittsburgh-CSD-Khalifa Introduction Function A self-contained program segment that carries out some specific, well-defined

More information

UNIT IV 2 MARKS. ( Word to PDF Converter - Unregistered ) FUNDAMENTALS OF COMPUTING & COMPUTER PROGRAMMING

UNIT IV 2 MARKS. ( Word to PDF Converter - Unregistered )   FUNDAMENTALS OF COMPUTING & COMPUTER PROGRAMMING ( Word to PDF Converter - Unregistered ) http://www.word-to-pdf-converter.net FUNDAMENTALS OF COMPUTING & COMPUTER PROGRAMMING INTRODUCTION TO C UNIT IV Overview of C Constants, Variables and Data Types

More information

Chapter 2, Part I Introduction to C Programming

Chapter 2, Part I Introduction to C Programming Chapter 2, Part I Introduction to C Programming C How to Program, 8/e, GE 2016 Pearson Education, Ltd. All rights reserved. 1 2016 Pearson Education, Ltd. All rights reserved. 2 2016 Pearson Education,

More information

Variables in C. Variables in C. What Are Variables in C? CMSC 104, Fall 2012 John Y. Park

Variables in C. Variables in C. What Are Variables in C? CMSC 104, Fall 2012 John Y. Park Variables in C CMSC 104, Fall 2012 John Y. Park 1 Variables in C Topics Naming Variables Declaring Variables Using Variables The Assignment Statement 2 What Are Variables in C? Variables in C have the

More information

Multiple Choice Questions ( 1 mark)

Multiple Choice Questions ( 1 mark) Multiple Choice Questions ( 1 mark) Unit-1 1. is a step by step approach to solve any problem.. a) Process b) Programming Language c) Algorithm d) Compiler 2. The process of walking through a program s

More information

Lecture 2 Tao Wang 1

Lecture 2 Tao Wang 1 Lecture 2 Tao Wang 1 Objectives In this chapter, you will learn about: Modular programs Programming style Data types Arithmetic operations Variables and declaration statements Common programming errors

More information

A A B U n i v e r s i t y

A A B U n i v e r s i t y A A B U n i v e r s i t y Faculty of Computer Sciences O b j e c t O r i e n t e d P r o g r a m m i n g Week 4: Introduction to Classes and Objects Asst. Prof. Dr. M entor Hamiti mentor.hamiti@universitetiaab.com

More information

CSE101-lec#12. Designing Structured Programs Introduction to Functions. Created By: Amanpreet Kaur & Sanjeev Kumar SME (CSE) LPU

CSE101-lec#12. Designing Structured Programs Introduction to Functions. Created By: Amanpreet Kaur & Sanjeev Kumar SME (CSE) LPU CSE101-lec#12 Designing Structured Programs Introduction to Functions Created By: Amanpreet Kaur & Sanjeev Kumar SME (CSE) LPU Outline Designing structured programs in C: Counter-controlled repetition

More information

Faculty of Engineering Computer Engineering Department Islamic University of Gaza C++ Programming Language Lab # 6 Functions

Faculty of Engineering Computer Engineering Department Islamic University of Gaza C++ Programming Language Lab # 6 Functions Faculty of Engineering Computer Engineering Department Islamic University of Gaza 2013 C++ Programming Language Lab # 6 Functions C++ Programming Language Lab # 6 Functions Objective: To be familiar with

More information

CS102: Variables and Expressions

CS102: Variables and Expressions CS102: Variables and Expressions The topic of variables is one of the most important in C or any other high-level programming language. We will start with a simple example: int x; printf("the value of

More information

C Syntax Out: 15 September, 1995

C Syntax Out: 15 September, 1995 Burt Rosenberg Math 220/317: Programming II/Data Structures 1 C Syntax Out: 15 September, 1995 Constants. Integer such as 1, 0, 14, 0x0A. Characters such as A, B, \0. Strings such as "Hello World!\n",

More information

(Refer Slide Time: 00:23)

(Refer Slide Time: 00:23) In this session, we will learn about one more fundamental data type in C. So, far we have seen ints and floats. Ints are supposed to represent integers and floats are supposed to represent real numbers.

More information

Functions in C SHARDA UNIVERSITY. Presented By: Pushpendra K. Rajput Assistant Professor

Functions in C SHARDA UNIVERSITY. Presented By: Pushpendra K. Rajput Assistant Professor Functions in C Presented By: Pushpendra K. Rajput Assistant Professor 1 Introduction Call a mechanic You face a problem in your car It repeats many times. No need to instruct Continue with your job Mechanic

More information

Government Polytechnic Muzaffarpur.

Government Polytechnic Muzaffarpur. Government Polytechnic Muzaffarpur. Name of the Lab: COMPUTER PROGRAMMING LAB (MECH. ENGG. GROUP) Subject Code: 1625408 Experiment: 1 Aim: Programming exercise on executing a C program. If you are looking

More information

CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York

CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York CSc 10200! Introduction to Computing Lecture 2-3 Edgardo Molina Fall 2013 City College of New York 1 C++ for Engineers and Scientists Third Edition Chapter 2 Problem Solving Using C++ 2 Objectives In this

More information

c) Comments do not cause any machine language object code to be generated. d) Lengthy comments can cause poor execution-time performance.

c) Comments do not cause any machine language object code to be generated. d) Lengthy comments can cause poor execution-time performance. 2.1 Introduction (No questions.) 2.2 A Simple Program: Printing a Line of Text 2.1 Which of the following must every C program have? (a) main (b) #include (c) /* (d) 2.2 Every statement in C

More information