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

Save this PDF as:
 WORD  PNG  TXT  JPG

Size: px
Start display at page:

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

Transcription

1 UNIT - I Introduction to C Programming

2 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 closely associated with the UNIX operating system where it was developed, since both the system and most of the programs that run on it are written in C.

3 Introduction to C It is a language with features economy of expression, modern flow control and data structures, and a rich set of operators. The language, however, is not tied to any one operating system or machine; and although it has been called a ``system programming language'' because it is useful for writing compilers and operating systems.

4 Introduction to C C provides the fundamental control-flow constructions required for well-structured programs: statement grouping, decision making (if-else), selecting one of a set of possible values (switch), looping with the termination test at the top (while, for) or at the bottom (do), and early loop exit (break).

5 Simple structure of a C program Inclusion of header files Inclusion of main( ) function Declaration Part i.e. Declaration of variables with corresponding Data types. Set of instructions using C syntax. End of Program statement

6 Simple Program /* Comment statements */ /* The Hello World program */ Preprocessor directives main() { Program statements; } # include <stdio.h> main() { printf( Hello World\n ); }

7 Sample C program # include<stdio.h> main( ) { int a, b, c, sum; a = 1; b = 2; c = 3; sum = a + b + c; printf("sum is %d", sum); }

8 Formal Structure of C Documentation section Link section Definition section Global declaration Main( ) Function section { Declaration Part, Executable Part } Subprogram section Function 1 Function 2 (User defined Function) Function n

9 The documentation section consists of a set of comment lines giving the name of the program, the author and other details. The link section provides instruction to the compiler to link function from the system library. The definition section defines all symbolic constants. There are some variables that are used in more than one function. Such variables are called global variables. Main() function two parts, declaration and executable part. The Declaration part declares all the variables used in executable part.

10 The program execution begins at the opening brace and ends at the closing braces. The closing braces of the main() function section is the logical end of the program. The subprogram section contains all the userdefined functions that are called in the main() function. User-defined functions are generally placed immediately after the main() function.

11 Executing a C program 1. Creating the program. 2. Compiling the program. 3. Linking the program with function that are needed from the C library. 4. Executing the program.

12 Points to remember 1. Every C program requires a main() function (use of more than one main() is illegal). 2. The execution of a function begins at the opening brace of the function and ends at the corresponding close brace. 3. C programs are written in lowercase letters. However, uppercase letters are used for symbolic names and output strings. 4. Al the programming words must be separated by at least one space. 5. Every program statement in a C program must end with a Semicolon(;)

13 The C character Set C uses uppercase letters A to Z, the lowercase letters a to z, the digits 0 to 9, and certain special characters as building blocks to form basic program. The special characters are listed below. + - * / = % & #!? ^ ~ \ < > ( ) [ ] { } : ;., _ $

14 The C character Set C uses certain combinations of these characters, such as \b, \n, and \t, to represent special conditions such as backspace, newline, and horizontal tab, respectively. These character combinations are known as escape sequences.

15 Identifiers and Keywords Identifiers are names that are given to various program elements, such as variables, functions and arrays. Identifiers consists of letters and digits, in any order, except that the first character must be a letter. Both upper and lower case letters are permitted. The underscore character ( _) can also be included, and is considered to be a letter.

16 Valid identifiers X y12 sum_1 _temperature Name area tax_rate TABLE Invalid Identifiers 4 th the first character must be a letter x Illegal character ( ) Order-no Illegal character (-) Error flag Illegal character (blank space)

17 Keywords There are certain reserved words, called keywords, that have standard, predefined meaning in C. The keyword can be used only for their intended purpose. E.g. auto extern sizeof break static case for struct char goto switch if int double union Void do while else return

18 Data types C language is rich in its data types. The variety of data types available allow the programmer to select the type appropriate to the needs of the applications as well as the machine The fundamental data types, namely integer (int), character (char), floating point (float), and doubleprecision floating point (double)

19 Data types Type Size (bits) Range Char to 127 Integer 16-32, 768 to 32, 767 Float E-38 to 3.4E+38 Double E-308 to 1.7E+308 Declaration of variables int count; Int number, total; Char s;

20 User-Defined data types C supports a feature known as type definition that allows users to define an identifier that would represent an existing data type. Format : typedef type identifier; Where type refers to an existing data type and identifier refers to the new name given to the data type.

21 typedef int units; typedef float marks; Here, units symbolizes int and marks symbolizes float. units batch1, batch2; marks name1[50], name2[50]; batch1 and batch2 are declared as int variable and name1[50] and name2[50] are declared as 50 element floating point array variables.

22 Constants Constants in C refers to fixed value that do not change during the execution of a program. Integer consist of a set of digits, 0 to 9, preceded by an optional or + sign. Valid constants are

23 Invalid constants ,000 $1000 Real constants These constants are represented by number containing fractional parts like e.g

24 Character Constant A single character constant contains a single character enclosed within a pair of single quote marks. E.g. 5 X Note that the character constant 5 is not same as number 5. the last constant is blank space. Character constant have integer values known as ASCII values printf( %d, a ); > will print the number 97 printf( %c, 97 ); > will print the letter a

25 String Constant A string constant is a sequence of characters enclosed in double quotes. The character may be letters, number, special characters and blank space. E.g. Hello 1987 X Remember that a character constant X is not equivalent to the single character constant X.

26 Backslash Character Constant constant Meaning \a Audible alert \b Back space \n New line \t Horizontal tab \v Vertical tab \0 Null \\ Backslash \ Single quote \ Double quote

27 VARIABLES A variable is a data name that may be used to store a data value. A variable may take different values at different times during execution. A variable name can be chosen by the programmer in a meaningful way. Valid: john Value T_raise sum1 mark Invalid: 123 (area)

28 First_tag char Price$ group one average_number int_type Variable Declaration Syntax: datatype v1,v2,.., vn; Variables are separated by commas, and declaration statement must end with a semicolon. E.g. int count; int number, total;

29 ARRAYS A array is a kind of variable that is used extensively in C. An array is an identifier that refers to a collection of data items that all have the same name. The data items must all be of the same type (e.g. all integers, all characters). The individual data item are represented by their corresponding array element. E.g. int a[10]; a[0] a[1] a[2] a[3] a[4] a[5] a[6] a[7] a[8] a[9]

30 ARRAYS E.g. int a[5]; The values of array element can be assigned as follows. a[0]=35; a[1]=40; a[2]=20; a[3]=57; a[4]=19; This would cause the array a to store values as shown below. a[0] a[1] a[2] a[3] a[4]

31 ARRAYS The following are the valid statements : A = a[0] + 10; A[4] = a[0] + a[2]; Value[6] = a[3] * 6; E.g. float height[50]; Which declares the height to be an array containing 50 real elements. The C language treats character strings simply as array of characters. The size in a character string represents the maximum number of characters that a string can hold.

32 ARRAYS E.g. char name[10]; Declares the name as a character array variable that can hold a maximum of 10 characters. Suppose WELL DONE is a string that is stored in the memory as follows: We must always allow one extra element space for the null terminator. W E L L D O N E \0

33 Two-Dimensional Arrays Organized in the form of rows and columns E.g. int a[5][5]; a[0] a[1] a[2] a[3] a[4] a[5] a[0] a[1] a[2] a[3] a[4] a[5]

34 for (i=1;i<=5;i++) { for(j=1;j<=5;j++) { Scanf( %d, &a[ i ] [ j ]); } }

35 Operators and Expressions C operators can be classified into a number of categories. They include: 1. Arithmetic operators. 2. Relational operators. 3. Logical operators. 4. Assignment operators 5. Increment and decrement operators 6. Conditional operators.

36 1. Arithmetic operators C provides all the basic arithmetic operators as given below: operator Meaning + Addition - Subtraction * Multiplication / Division % Modulo division E.g. a+b; a-b; a*b; a/b; a%b;

37 2. Relational operators The comparison can be done by relational operator. The expression (a < b or 1 < 20) containing a relational operator is termed as a relational expression. If the relation is true it is one or the relation is false it is zero. operator Meaning < is less than > is greater than <= is less than or equal to >= is greater than or equal to == is equal to!= is not equal to

38 3. Logical operators C has he following three logical operators. operator Meaning && logical AND logical OR! Logical NOT The logical operators && and are used when we want to test more than one condition and make decision. E.g. (a > b && x ==10)

39 4. Assignment operator Assignment operators are used to assign the result of an expression to a variable. E.g. C=a+b; In addition, C has a set of shorthand assignment operators of the form: Stmt. with simple Stmt. with assgn. Operator shorthand operator a=a+1 a+=1 a=a-1 a-=1 a=a*(n+1) a*=n+1 Note: 1) what appears on the left-side need not be repeated and therefore easier to write 2) the statement is more efficient.

40 5. Increment and decrement operators C has two very useful operators not generally found in other languages. These are increment ( + + )and decrement operators ( - - ). The operator + + adds 1, while - - subtracts1. E.g. + + m; and m + +; mean the same thing when they form statements independently. They behave differently when they are used in the expressions on the right-hand side of an assignment statement. Consider the following.

41 5. Increment and decrement operators M = 5; Y= + + m; In this case, the value of y and m would be 6. suppose if we rewrite the above statement as M = 5; Y= m + +; Then, the value of y would be 5 and m would be 6.

42 5. Increment and decrement operators The unusual feature of `+ +' and `- -' is that they can be used either before or after a variable. The value of + + k is the value of k after it has been incremented. The value of k + + is k before it is incremented. E.g. Suppose k is 5. Then x = + + k; Increments k to 6 and then sets x to the resulting value, i.e., to 6. But x = k++; first sets x to 5, and then increments k to 6. The incrementing effect of ++k and k++ is the same, but their values are respectively 5 and 6.

43 6. Conditional operator A ternary operator pair? : is available in C to construct conditional expressions of the form: exp1? exp2 : exp3; Where exp1, exp2, exp3 are expressions. First exp1 is evaluated, if it is non zero (true) then the exp2 is evaluated and becomes the value of the expression. If exp1 is false, exp3 is evaluated and its value becomes the value of the expression. e.g. A=10; b=15; x=(a>b)? a : b; If (a>b) X=a; Else X=b; is same as

44 Arithmetic expressions An arithmetic expression is a combination of variables, constants, and operators arranged as per the syntax of the language. C language can handle complex mathematical expressions. algebraic expressions C expressions a x b c a * b c (m+n) (x+y) (m+n) * (x+y) ab c a * b / c 3x 2 + 2x * x * X + 2 * X + 1 x + c y x / y + c

45 Precedence of Arithmetic operator An arithmetic expression without parenthesis will be evaluated from left to right using the rules of precedence of operators. There are two distinct priority levels of arithmetic operators in C. High priority * / % Low priority + - During the first pass, the high priority operators are applied as they are encountered. During the second pass, the low priority operators are applied as they are encountered.

46 Library functions The C language is accompanied by a number library functions that carry out various commonly used operations or calculations. There are some library functions that carry out standard input / output operations (e.g. read and write characters, read and write numbers, open and close files, etc). Functions that perform operations on characters (e.g. convert from lower- to upper) functions that performs operations on strings (e.g. copy a string, compare a string, concatenate strings, etc). Library functions that are functionally similar are usually grouped together as (compiled) object program in separate library files. A typical set of library functions will include a fairly large number of functions that are common to most C compilers.

47 Library functions abs(i) - return the absolute value of i. ceil(d) - round up to the next integer value. cos(d) - return the cosine of d. log(d) - return the natural logarithm of d. printf(.) - send data items to the standard output device. scanf( ) - enter data items from the standard input device. tolower(c) - convert letter to lowercase. toupper(c) - convert letter to uppercase. getchar( ) - enter a character from a standard input device. putchar( ) - send a character to the standard output device. sqrt(d) - returns a square root of d.

48 Library functions A library function is accessed simply by writing the function name, followed by a list of arguments that represent information being passed to a function. The arguments must be enclosed in parentheses and separated by commas. The arguments can be constants, variable names, or more complex expressions

49 Data input and output SINGLE CHARACTER INPUT THE getchar( ) FUNCTION Single character can be entered into the computer using the C library function getchar( ). The getchar( ) function is a part of the standard C I/O library. It returns a single character from a standard input device (typically a keyboard). The function does not require any arguments, though a pair of empty parentheses must follow the word getchar( ). SYNTAX: character variable = getchar( ); E.g. char c; c = getchar( );

50 Data input and output SINGLE CHARACTER OUTPUT THE putchar( ) FUNCTION Single character can be displayed using C library function putchar(). It transmits a single character to a standard output device ( typically a monitor) It must be expressed as an argument to the function, enclosed in parentheses, following the word putchar( ). SYNTAX: putchar (character variable ); E.g. char c; putchar(c);

51 Entering input data The scanf Function Input data can be entered into the computer from a standard input device by means of the C library function scanf. This function can be used to enter any combination of numerical values, single characters and strings. The function returns the number of data items that have been entered successfully. syntax: scanf( control string, arg1, arg2,.... argn); Where control string refers to a string containing certain required formatting information, and arg1, arg2,... argn are arguments that represent the individual input data items. The control string consists of individual groups of characters with one character group for each input data item.

52 Entering input data The scanf Function Each character group must begin with a percent sign (%). Conversion character c d f h i o x s Data item is a single character Data item is a decimal integer Meaning Data item is a floating-point value Data item is a short integer Data item is a decimal, hexadecimal or octal integer Data item is an octal integer Data item is a hexadecimal integer Data item is a string (null \0 will automatically added at end)

53 Entering output data The printf function Output data can be written from the computer onto a standard output device using the C library function printf. This function can be used to output any numerical values, ingle character and strings. The printf function moves data from the computer s memory to the standard output device. syntax: printf( control string, arg1, arg2,.... argn);

54 Conversion character c d f i o x s Meaning Data item is displayed as single character Data item is displayed as decimal integer Data item is displayed as floating-point value Data item is displayed as signed decimal integer Data item is displayed as octal integer Data item is displayed as hexadecimal integer Data item is displayed as string

55 Assignment C datatypes 2. Variables and Arrays. Submission date: 04/10/2007

56 END OF UNIT - I

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

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

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

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

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

Data types, variables, constants

Data types, variables, constants Data types, variables, constants 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 in C 2.6 Decision

More information

Programming in C and Data Structures [15PCD13/23] 1. PROGRAMMING IN C AND DATA STRUCTURES [As per Choice Based Credit System (CBCS) scheme]

Programming in C and Data Structures [15PCD13/23] 1. PROGRAMMING IN C AND DATA STRUCTURES [As per Choice Based Credit System (CBCS) scheme] Programming in C and Data Structures [15PCD13/23] 1 PROGRAMMING IN C AND DATA STRUCTURES [As per Choice Based Credit System (CBCS) scheme] Course objectives: The objectives of this course is to make students

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

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

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

COMPUTER SCIENCE HIGHER SECONDARY FIRST YEAR. VOLUME II - CHAPTER 10 PROBLEM SOLVING TECHNIQUES AND C PROGRAMMING 1,2,3 & 5 MARKS

COMPUTER SCIENCE HIGHER SECONDARY FIRST YEAR.  VOLUME II - CHAPTER 10 PROBLEM SOLVING TECHNIQUES AND C PROGRAMMING 1,2,3 & 5 MARKS COMPUTER SCIENCE HIGHER SECONDARY FIRST YEAR VOLUME II - CHAPTER 10 PROBLEM SOLVING TECHNIQUES AND C PROGRAMMING 1,2,3 & 5 MARKS S.LAWRENCE CHRISTOPHER, M.C.A., B.Ed., LECTURER IN COMPUTER SCIENCE PONDICHERRY

More information

C OVERVIEW BASIC C PROGRAM STRUCTURE. C Overview. Basic C Program Structure

C OVERVIEW BASIC C PROGRAM STRUCTURE. C Overview. Basic C Program Structure C Overview Basic C Program Structure C OVERVIEW BASIC C PROGRAM STRUCTURE Goals The function main( )is found in every C program and is where every C program begins speed execution portability C uses braces

More information

Unit 1: Introduction to C Language. Saurabh Khatri Lecturer Department of Computer Technology VIT, Pune

Unit 1: Introduction to C Language. Saurabh Khatri Lecturer Department of Computer Technology VIT, Pune Unit 1: Introduction to C Language Saurabh Khatri Lecturer Department of Computer Technology VIT, Pune Introduction to C Language The C programming language was designed by Dennis Ritchie at Bell Laboratories

More information

CHAPTER-6 GETTING STARTED WITH C++

CHAPTER-6 GETTING STARTED WITH C++ CHAPTER-6 GETTING STARTED WITH C++ TYPE A : VERY SHORT ANSWER QUESTIONS 1. Who was developer of C++? Ans. The C++ programming language was developed at AT&T Bell Laboratories in the early 1980s by Bjarne

More information

Unit 4. Input/Output Functions

Unit 4. Input/Output Functions Unit 4 Input/Output Functions Introduction to Input/Output Input refers to accepting data while output refers to presenting data. Normally the data is accepted from keyboard and is outputted onto the screen.

More information

STUDY NOTES UNIT 1 - INTRODUCTION TO OBJECT ORIENTED PROGRAMMING

STUDY NOTES UNIT 1 - INTRODUCTION TO OBJECT ORIENTED PROGRAMMING OBJECT ORIENTED PROGRAMMING STUDY NOTES UNIT 1 - INTRODUCTION TO OBJECT ORIENTED PROGRAMMING 1. Object Oriented Programming Paradigms 2. Comparison of Programming Paradigms 3. Basic Object Oriented Programming

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

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

Operators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur

Operators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur Operators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur Operators and Expressions 8/24/2012 Dept of CS&E 2 Arithmetic operators Relational operators Logical operators

More information

Introduction to C# Applications

Introduction to C# Applications 1 2 3 Introduction to C# Applications OBJECTIVES To write simple C# applications To write statements that input and output data to the screen. To declare and use data of various types. To write decision-making

More information

C Programming

C Programming 204216 -- C Programming Chapter 3 Processing and Interactive Input Adapted/Assembled for 204216 by Areerat Trongratsameethong A First Book of ANSI C, Fourth Edition Objectives Assignment Mathematical Library

More information

UNIT-I Input/ Output functions and other library functions

UNIT-I Input/ Output functions and other library functions Input and Output functions UNIT-I Input/ Output functions and other library functions All the input/output operations are carried out through function calls. There exists several functions that become

More information

ME 172. Sourav Saha. Md. Mahamudul Hossain Kazi Fazle Rabbi Saddam Hossain Joy Kamruzzaman Lecturer,Dept. of ME,BUET

ME 172. Sourav Saha. Md. Mahamudul Hossain Kazi Fazle Rabbi Saddam Hossain Joy Kamruzzaman Lecturer,Dept. of ME,BUET ME 172 Introduction to C Programming Language Sourav Saha Md. Mahamudul Hossain Kazi Fazle Rabbi Saddam Hossain Joy Kamruzzaman Lecturer,Dept. of ME,BUET Courtesy: Dr. Noor Al-Quddus Cyrus Ashok Arupratan

More information

Unit-II Programming and Problem Solving (BE1/4 CSE-2)

Unit-II Programming and Problem Solving (BE1/4 CSE-2) Unit-II Programming and Problem Solving (BE1/4 CSE-2) Problem Solving: Algorithm: It is a part of the plan for the computer program. An algorithm is an effective procedure for solving a problem in a finite

More information

JAVA Programming Fundamentals

JAVA Programming Fundamentals Chapter 4 JAVA Programming Fundamentals By: Deepak Bhinde PGT Comp.Sc. JAVA character set Character set is a set of valid characters that a language can recognize. It may be any letter, digit or any symbol

More information

Fundamentals of Programming

Fundamentals of Programming Fundamentals of Programming Lecture 3 - Constants, Variables, Data Types, And Operations Lecturer : Ebrahim Jahandar Borrowed from lecturer notes by Omid Jafarinezhad Outline C Program Data types Variables

More information

C Fundamentals & Formatted Input/Output. adopted from KNK C Programming : A Modern Approach

C Fundamentals & Formatted Input/Output. adopted from KNK C Programming : A Modern Approach C Fundamentals & Formatted Input/Output adopted from KNK C Programming : A Modern Approach C Fundamentals 2 Program: Printing a Pun The file name doesn t matter, but the.c extension is often required.

More information

C Programming Multiple. Choice

C Programming Multiple. Choice C Programming Multiple Choice Questions 1.) Developer of C language is. a.) Dennis Richie c.) Bill Gates b.) Ken Thompson d.) Peter Norton 2.) C language developed in. a.) 1970 c.) 1976 b.) 1972 d.) 1980

More information

Fundamentals of C. Structure of a C Program

Fundamentals of C. Structure of a C Program Fundamentals of C Structure of a C Program 1 Our First Simple Program Comments - Different Modes 2 Comments - Rules Preprocessor Directives Preprocessor directives start with # e.g. #include copies a file

More information

LECTURE 02 INTRODUCTION TO C++

LECTURE 02 INTRODUCTION TO C++ PowerPoint Slides adapted from *Starting Out with C++: From Control Structures through Objects, 7/E* by *Tony Gaddis* Copyright 2012 Pearson Education Inc. COMPUTER PROGRAMMING LECTURE 02 INTRODUCTION

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

2.1. Chapter 2: Parts of a C++ Program. Parts of a C++ Program. Introduction to C++ Parts of a C++ Program

2.1. Chapter 2: Parts of a C++ Program. Parts of a C++ Program. Introduction to C++ Parts of a C++ Program Chapter 2: Introduction to C++ 2.1 Parts of a C++ Program Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Parts of a C++ Program Parts of a C++ Program // sample C++ program

More information

Advantages of writing algorithm

Advantages of writing algorithm Advantages of writing algorithm Effective communication: Algorithm is written using English like language,algorithm is better way of communicating the logic to the concerned people Effective Analysis:

More information

Data Type Fall 2014 Jinkyu Jeong

Data Type Fall 2014 Jinkyu Jeong Data Type Fall 2014 Jinkyu Jeong (jinkyu@skku.edu) 1 Syntax Rules Recap. keywords break double if sizeof void case else int static... Identifiers not#me scanf 123th printf _id so_am_i gedd007 Constants

More information

3. EXPRESSIONS. It is a sequence of operands and operators that reduce to a single value.

3. EXPRESSIONS. It is a sequence of operands and operators that reduce to a single value. 3. EXPRESSIONS It is a sequence of operands and operators that reduce to a single value. Operator : It is a symbolic token that represents an action to be taken. Ex: * is an multiplication operator. Operand:

More information

File Handling in C. EECS 2031 Fall October 27, 2014

File Handling in C. EECS 2031 Fall October 27, 2014 File Handling in C EECS 2031 Fall 2014 October 27, 2014 1 Reading from and writing to files in C l stdio.h contains several functions that allow us to read from and write to files l Their names typically

More information

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program Objectives Chapter 2: Basic Elements of C++ In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates

More information

Introduction to C. History of C:

Introduction to C. History of C: History of C: Introduction to C C is a structured/procedure oriented, high-level and machine independent programming language. The root of all modern languages is ALGOL, introduced in the early 1960. In

More information

CS1100 Introduction to Programming

CS1100 Introduction to Programming CS1100 Introduction to Programming Arrays Madhu Mutyam Department of Computer Science and Engineering Indian Institute of Technology Madras Course Material SD, SB, PSK, NSN, DK, TAG CS&E, IIT M 1 An Array

More information

Program Fundamentals

Program Fundamentals Program Fundamentals /* HelloWorld.java * The classic Hello, world! program */ class HelloWorld { public static void main (String[ ] args) { System.out.println( Hello, world! ); } } /* HelloWorld.java

More information

JME Language Reference Manual

JME Language Reference Manual JME Language Reference Manual 1 Introduction JME (pronounced jay+me) is a lightweight language that allows programmers to easily perform statistic computations on tabular data as part of data analysis.

More information

Chapter 9 Strings. With this array declaration: char s[10];

Chapter 9 Strings. With this array declaration: char s[10]; Chapter 9 Strings 9.1 Chapter Overview There is no data type in C called ʻstringʼ; instead, strings are represented by an array of characters. There is an assortment of useful functions for strings that

More information

Muntaser Abulafi Yacoub Sabatin Omar Qaraeen. C Data Types

Muntaser Abulafi Yacoub Sabatin Omar Qaraeen. C Data Types Programming Fundamentals for Engineers 0702113 5. Basic Data Types Muntaser Abulafi Yacoub Sabatin Omar Qaraeen 1 2 C Data Types Variable definition C has a concept of 'data types' which are used to define

More information

Gabriel Hugh Elkaim Spring CMPE 013/L: C Programming. CMPE 013/L: C Programming

Gabriel Hugh Elkaim Spring CMPE 013/L: C Programming. CMPE 013/L: C Programming 1 Literal Constants Definition A literal or a literal constant is a value, such as a number, character or string, which may be assigned to a variable or a constant. It may also be used directly as a function

More information

CS313D: ADVANCED PROGRAMMING LANGUAGE

CS313D: ADVANCED PROGRAMMING LANGUAGE CS313D: ADVANCED PROGRAMMING LANGUAGE Computer Science department Lecture 2 : C# Language Basics Lecture Contents 2 The C# language First program Variables and constants Input/output Expressions and casting

More information

Chapter 1 Introduction to Computers and C++ Programming

Chapter 1 Introduction to Computers and C++ Programming Chapter 1 Introduction to Computers and C++ Programming 1 Outline 1.1 Introduction 1.2 What is a Computer? 1.3 Computer Organization 1.7 History of C and C++ 1.14 Basics of a Typical C++ Environment 1.20

More information

Operators And Expressions

Operators And Expressions Operators And Expressions Operators Arithmetic Operators Relational and Logical Operators Special Operators Arithmetic Operators Operator Action Subtraction, also unary minus + Addition * Multiplication

More information

Contents. Jairo Pava COMS W4115 June 28, 2013 LEARN: Language Reference Manual

Contents. Jairo Pava COMS W4115 June 28, 2013 LEARN: Language Reference Manual Jairo Pava COMS W4115 June 28, 2013 LEARN: Language Reference Manual Contents 1 Introduction...2 2 Lexical Conventions...2 3 Types...3 4 Syntax...3 5 Expressions...4 6 Declarations...8 7 Statements...9

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

Chapter 1 Problem Solving using Computer

Chapter 1 Problem Solving using Computer Computer Programming in C Chapter 1 Problem Solving using Computer What is a problem? Problem is defined as the difference between an existing situation and a desired situation, that is, in accordance

More information

EL2310 Scientific Programming

EL2310 Scientific Programming Lecture 7: Introduction to C (pronobis@kth.se) Overview Overview Lecture 7: Introduction to C Wrap Up Basic Datatypes and printf Branching and Loops in C Constant values Wrap Up Lecture 7: Introduction

More information

C++ Basics. Lecture 2 COP 3014 Spring January 8, 2018

C++ Basics. Lecture 2 COP 3014 Spring January 8, 2018 C++ Basics Lecture 2 COP 3014 Spring 2018 January 8, 2018 Structure of a C++ Program Sequence of statements, typically grouped into functions. function: a subprogram. a section of a program performing

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

CpSc 111 Lab 3 Integer Variables, Mathematical Operations, & Redirection

CpSc 111 Lab 3 Integer Variables, Mathematical Operations, & Redirection CpSc 111 Lab 3 Integer Variables, Mathematical Operations, & Redirection Overview By the end of the lab, you will be able to: declare variables perform basic arithmetic operations on integer variables

More information

C Program. Output. Hi everyone. #include <stdio.h> main () { printf ( Hi everyone\n ); }

C Program. Output. Hi everyone. #include <stdio.h> main () { printf ( Hi everyone\n ); } C Program Output #include main () { printf ( Hi everyone\n ); Hi everyone #include main () { printf ( Hi everyone\n ); #include and main are Keywords (or Reserved Words) Reserved Words

More information

CpSc 1011 Lab 3 Integer Variables, Mathematical Operations, & Redirection

CpSc 1011 Lab 3 Integer Variables, Mathematical Operations, & Redirection CpSc 1011 Lab 3 Integer Variables, Mathematical Operations, & Redirection Overview By the end of the lab, you will be able to: declare variables perform basic arithmetic operations on integer variables

More information

Computer Programming CS F111

Computer Programming CS F111 Computer Programming CS F111 BITS Pilani Dubai Campus NAND KUMAR Basics of C Programming BITS Pilani Dubai Campus Write a program that 1. Asks 5 marks from the user, find the average of the marks and print

More information

XSEDE Scholars Program Introduction to C Programming. John Lockman III June 7 th, 2012

XSEDE Scholars Program Introduction to C Programming. John Lockman III June 7 th, 2012 XSEDE Scholars Program Introduction to C Programming John Lockman III June 7 th, 2012 Homework 1 Problem 1 Find the error in the following code #include int main(){ } printf(find the error!\n");

More information

Basic Types and Formatted I/O

Basic Types and Formatted I/O Basic Types and Formatted I/O C Variables Names (1) Variable Names Names may contain letters, digits and underscores The first character must be a letter or an underscore. the underscore can be used but

More information

Dept. of CSE, IIT KGP

Dept. of CSE, IIT KGP Control Flow: Looping CS10001: Programming & Data Structures Pallab Dasgupta Professor, Dept. of Computer Sc. & Engg., Indian Institute of Technology Kharagpur Types of Repeated Execution Loop: Group of

More information

Operators & Expressions

Operators & Expressions Operators & Expressions Operator An operator is a symbol used to indicate a specific operation on variables in a program. Example : symbol + is an add operator that adds two data items called operands.

More information

VALLIAMMAI ENGINEERING COLLEGE SRM NAGAR, KATTANGULATHUR

VALLIAMMAI ENGINEERING COLLEGE SRM NAGAR, KATTANGULATHUR VALLIAMMAI ENGINEERING COLLEGE SRM NAGAR, KATTANGULATHUR 603 203 FIRST SEMESTER B.E / B.Tech., (Common to all Branches) QUESTION BANK - GE 6151 COMPUTER PROGRAMMING UNIT I - INTRODUCTION Generation and

More information

c++ keywords: ( all lowercase ) Note: cin and cout are NOT keywords.

c++ keywords: ( all lowercase ) Note: cin and cout are NOT keywords. Chapter 1 File Extensions: Source code (cpp), Object code (obj), and Executable code (exe). Preprocessor processes directives and produces modified source Compiler takes modified source and produces object

More information

1. What type of error produces incorrect results but does not prevent the program from running? a. syntax b. logic c. grammatical d.

1. What type of error produces incorrect results but does not prevent the program from running? a. syntax b. logic c. grammatical d. Gaddis: Starting Out with Python, 2e - Test Bank Chapter Two MULTIPLE CHOICE 1. What type of error produces incorrect results but does not prevent the program from running? a. syntax b. logic c. grammatical

More information

Operators and Control Flow. CS449 Fall 2017

Operators and Control Flow. CS449 Fall 2017 Operators and Control Flow CS449 Fall 2017 Running Example #include /* header file */ int main() { int grade, count, total, average; /* declaramons */ count = 0; /* inimalizamon */ total = 0;

More information

Computer programming & Data Structures Unit I Introduction to Computers

Computer programming & Data Structures Unit I Introduction to Computers Computer programming & Data Structures Unit I Introduction to Computers (1) What are system software and application software? What are the differences between them? A piece of software is a program or

More information

Tokens, Expressions and Control Structures

Tokens, Expressions and Control Structures 3 Tokens, Expressions and Control Structures Tokens Keywords Identifiers Data types User-defined types Derived types Symbolic constants Declaration of variables Initialization Reference variables Type

More information

CMSC 104 -Lecture 5 John Y. Park, adapted by C Grasso

CMSC 104 -Lecture 5 John Y. Park, adapted by C Grasso CMSC 104 -Lecture 5 John Y. Park, adapted by C Grasso 1 Topics Naming Variables Declaring Variables Using Variables The Assignment Statement 2 a + b Variables are notthe same thing as variables in algebra.

More information

Chapter 2 Elementary Programming

Chapter 2 Elementary Programming Chapter 2 Elementary Programming Part I 1 Motivations In the preceding chapter, you learned how to create, compile, and run a Java program. Starting from this chapter, you will learn how to solve practical

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

Programming with C++ as a Second Language

Programming with C++ as a Second Language Programming with C++ as a Second Language Week 2 Overview of C++ CSE/ICS 45C Patricia Lee, PhD Chapter 1 C++ Basics Copyright 2016 Pearson, Inc. All rights reserved. Learning Objectives Introduction to

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

Java Identifiers. Java Language Essentials. Java Keywords. Java Applications have Class. Slide Set 2: Java Essentials. Copyright 2012 R.M.

Java Identifiers. Java Language Essentials. Java Keywords. Java Applications have Class. Slide Set 2: Java Essentials. Copyright 2012 R.M. Java Language Essentials Java is Case Sensitive All Keywords are lower case White space characters are ignored Spaces, tabs, new lines Java statements must end with a semicolon ; Compound statements use

More information

L-System Fractal Generator: Language Reference Manual

L-System Fractal Generator: Language Reference Manual L-System Fractal Generator: Language Reference Manual Michael Eng, Jervis Muindi, Timothy Sun Contents 1 Program Definition 3 2 Lexical Conventions 3 2.1 Comments...............................................

More information

Chapter 21: Introduction to C Programming Language

Chapter 21: Introduction to C Programming Language Ref. Page Slide 1/65 Learning Objectives In this chapter you will learn about: Features of C Various constructs and their syntax Data types and operators in C Control and Loop Structures in C Functions

More information

Engineering Problem Solving with C++, Etter/Ingber

Engineering Problem Solving with C++, Etter/Ingber Engineering Problem Solving with C++, Etter/Ingber Chapter 2 Simple C++ Programs C++, Second Edition, J. Ingber 1 Simple C++ Programs Program Structure Constants and Variables C++ Operators Standard Input

More information

Problem Solving and 'C' Programming

Problem Solving and 'C' Programming Problem Solving and 'C' Programming Targeted at: Entry Level Trainees Session 15: Files and Preprocessor Directives/Pointers 2007, Cognizant Technology Solutions. All Rights Reserved. The information contained

More information

Binghamton University. CS-120 Summer Introduction to C. Text: Introduction to Computer Systems : Chapters 11, 12, 14, 13

Binghamton University. CS-120 Summer Introduction to C. Text: Introduction to Computer Systems : Chapters 11, 12, 14, 13 Introduction to C Text: Introduction to Computer Systems : Chapters 11, 12, 14, 13 Problem: Too Many Details For example: Lab 7 Bubble Sort Needed to keep track of too many details! Outer Loop When do

More information

Professor: Sana Odeh Lecture 3 Python 3.1 Variables, Primitive Data Types & arithmetic operators

Professor: Sana Odeh Lecture 3 Python 3.1 Variables, Primitive Data Types & arithmetic operators 1 Professor: Sana Odeh odeh@courant.nyu.edu Lecture 3 Python 3.1 Variables, Primitive Data Types & arithmetic operators Review What s wrong with this line of code? print( He said Hello ) What s wrong with

More information

ARG! Language Reference Manual

ARG! Language Reference Manual ARG! Language Reference Manual Ryan Eagan, Mike Goldin, River Keefer, Shivangi Saxena 1. Introduction ARG is a language to be used to make programming a less frustrating experience. It is similar to C

More information

Fundamentals of Programming Session 8

Fundamentals of Programming Session 8 Fundamentals of Programming Session 8 Instructor: Reza Entezari-Maleki Email: entezari@ce.sharif.edu 1 Fall 2013 These slides have been created using Deitel s slides Sharif University of Technology Outlines

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

Q1. Multiple Choice Questions

Q1. Multiple Choice Questions Rayat Shikshan Sanstha s S. M. Joshi College, Hadapsar Pune-28 F.Y.B.C.A(Science) Basic C Programing QUESTION BANK Q1. Multiple Choice Questions 1. Diagramatic or symbolic representation of an algorithm

More information

CS 151 Review #3. // More than one variable can be defined // in a statement. Multiple variables are // separated by a comma.

CS 151 Review #3. // More than one variable can be defined // in a statement. Multiple variables are // separated by a comma. REVIEW cout Statement The cout statement invokes an output stream, which is a sequence of characters to be displayed to the screen. cout

More information

CSCI 123 Introduction to Programming Concepts in C++

CSCI 123 Introduction to Programming Concepts in C++ CSCI 123 Introduction to Programming Concepts in C++ Brad Rippe C++ Basics C++ layout Include directive #include using namespace std; int main() { } statement1; statement; return 0; Every program

More information

Arithmetic Expressions in C

Arithmetic Expressions in C Arithmetic Expressions in C Arithmetic Expressions consist of numeric literals, arithmetic operators, and numeric variables. They simplify to a single value, when evaluated. Here is an example of an arithmetic

More information

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

Computer Programming & Problem Solving ( CPPS ) Turbo C Programming For The PC (Revised Edition ) By Robert Lafore 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

More information

MODULE 02: BASIC COMPUTATION IN JAVA

MODULE 02: BASIC COMPUTATION IN JAVA MODULE 02: BASIC COMPUTATION IN JAVA Outline Variables Naming Conventions Data Types Primitive Data Types Review: int, double New: boolean, char The String Class Type Conversion Expressions Assignment

More information

FRAC: Language Reference Manual

FRAC: Language Reference Manual FRAC: Language Reference Manual Justin Chiang jc4127 Kunal Kamath kak2211 Calvin Li ctl2124 Anne Zhang az2350 1. Introduction FRAC is a domain-specific programming language that enables the programmer

More information

CS201- Introduction to Programming Latest Solved Mcqs from Midterm Papers May 07,2011. MIDTERM EXAMINATION Spring 2010

CS201- Introduction to Programming Latest Solved Mcqs from Midterm Papers May 07,2011. MIDTERM EXAMINATION Spring 2010 CS201- Introduction to Programming Latest Solved Mcqs from Midterm Papers May 07,2011 Lectures 1-22 Moaaz Siddiq Asad Ali Latest Mcqs MIDTERM EXAMINATION Spring 2010 Question No: 1 ( Marks: 1 ) - Please

More information

CpSc 1111 Lab 4 Formatting and Flow Control

CpSc 1111 Lab 4 Formatting and Flow Control CpSc 1111 Lab 4 Formatting and Flow Control Overview By the end of the lab, you will be able to: use fscanf() to accept a character input from the user and print out the ASCII decimal, octal, and hexadecimal

More information

Variable and Data Type I

Variable and Data Type I The Islamic University of Gaza Faculty of Engineering Dept. of Computer Engineering Intro. To Computers (LNGG 1003) Lab 2 Variable and Data Type I Eng. Ibraheem Lubbad February 18, 2017 Variable is reserved

More information

Input And Output of C++

Input And Output of C++ Input And Output of C++ Input And Output of C++ Seperating Lines of Output New lines in output Recall: "\n" "newline" A second method: object endl Examples: cout

More information

Decaf Language Reference

Decaf Language Reference Decaf Language Reference Mike Lam, James Madison University Fall 2016 1 Introduction Decaf is an imperative language similar to Java or C, but is greatly simplified compared to those languages. It will

More information

CAMBRIDGE SCHOOL, NOIDA ASSIGNMENT 1, TOPIC: C++ PROGRAMMING CLASS VIII, COMPUTER SCIENCE

CAMBRIDGE SCHOOL, NOIDA ASSIGNMENT 1, TOPIC: C++ PROGRAMMING CLASS VIII, COMPUTER SCIENCE CAMBRIDGE SCHOOL, NOIDA ASSIGNMENT 1, TOPIC: C++ PROGRAMMING CLASS VIII, COMPUTER SCIENCE a) Mention any 4 characteristic of the object car. Ans name, colour, model number, engine state, power b) What

More information

Introduction To C Programming

Introduction To C Programming Introduction To C Programming You will learn basic programming concepts in a low level procedural language. Programming Languages There are many different languages - (Just a small sample): C, C++, C#,

More information

CpSc 1111 Lab 5 Formatting and Flow Control

CpSc 1111 Lab 5 Formatting and Flow Control CpSc 1111 Lab 5 Formatting and Flow Control Overview By the end of the lab, you will be able to: use fscanf() to accept a character input from the user execute a basic block iteratively using loops to

More information

Section 2.2 Your First Program in Java: Printing a Line of Text

Section 2.2 Your First Program in Java: Printing a Line of Text Chapter 2 Introduction to Java Applications Section 2.2 Your First Program in Java: Printing a Line of Text 2.2 Q1: End-of-line comments that should be ignored by the compiler are denoted using a. Two

More information

Fundamentals of Programming

Fundamentals of Programming Fundamentals of Programming Lecture 4 Input & Output Lecturer : Ebrahim Jahandar Borrowed from lecturer notes by Omid Jafarinezhad Outline printf scanf putchar getchar getch getche Input and Output in

More information