CSCI 3133 Programming with C Instructor: Bindra Shrestha University of Houston – Clear Lake.

Slides:



Advertisements
Similar presentations
11-2 Identify the parts of the “main” function, which include Preprocessor Directives main function header main function body which includes Declaration.
Advertisements

Lecture 2 Introduction to C Programming
Computer Programming Basics Assistant Professor Jeon, Seokhee Assistant Professor Department of Computer Engineering, Kyung Hee University, Korea.
Introduction to C Programming
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line.
Introduction to C Programming
Principles of Programming Fundamental of C Programming Language and Basic Input/Output Function 1.
Software Development Method. Assignments Due – Homework 0, Warmup Reading – Chapter 2 –
Structure of a C program
 2007 Pearson Education, Inc. All rights reserved Introduction to C Programming.
1 Key Concepts:  Why C?  Life Cycle Of a C program,  What is a computer program?  A program statement?  Basic parts of a C program,  Printf() function?
Data types and variables
Chapter 2 Data Types, Declarations, and Displays
Chapter 2: Introduction to C++.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the structure of a C-language program. ❏ To write your first C.
Introduction to C Programming
Data Types.
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
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.
Chapter 2 Getting Started in C Programming
A Variable is symbolic name that can be given different values. Variables are stored in particular places in the computer ‘s memory. When a variable is.
Input & Output: Console
C Tokens Identifiers Keywords Constants Operators Special symbols.
CPS120: Introduction to Computer Science Variables and Constants Lecture 8 - B.
CS1 Lesson 2 Introduction to C++ CS1 Lesson 2 -- John Cole1.
CPS120: Introduction to Computer Science
Lecture #5 Introduction to C++
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 2 Chapter 2 - Introduction to C Programming.
Chapter 2. C++ Program Structure C++ program is a collection of subprograms Subprograms in C++ are called FUNCTIONS Each function performs a specific.
Week 1 Algorithmization and Programming Languages.
Copyright © 2012 Pearson Education, Inc. Chapter 2: Introduction to C++
Course Title: Object Oriented Programming with C++ instructor ADEEL ANJUM Chapter No: 03 Conditional statement 1 BY ADEEL ANJUM (MSc-cs, CCNA,WEB DEVELOPER)
 Character set is a set of valid characters that a language can recognise.  A character represents any letter, digit or any other sign  Java uses the.
BASICS CONCEPTS OF ‘C’.  C Character Set C Character Set  Tokens in C Tokens in C  Constants Constants  Variables Variables  Global Variables Global.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 2: Introduction to C++
Introduction to Programming
Constants, Variables and Data types in C The C character Set A character denotes any alphabet, digit or special symbol used to represent information.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 2 - Introduction to C Programming Outline.
Tokens in C  Keywords  These are reserved words of the C language. For example int, float, if, else, for, while etc.  Identifiers  An Identifier is.
Types Chapter 2. C++ An Introduction to Computing, 3rd ed. 2 Objectives Observe types provided by C++ Literals of these types Explain syntax rules for.
 2007 Pearson Education, Inc. All rights reserved. A Simple C Program 1 /* ************************************************* *** Program: hello_world.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
1 C Syntax and Semantics Dr. Sherif Mohamed Tawfik Lecture Two.
Introduction C# program is collection of classes Classes are collection of methods and some statements That statements contains tokens C# includes five.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the structure of a C-language program. ❏ To write your first C.
1 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
Numbers in ‘C’ Two general categories: Integers Floats
Chapter 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
Introduction to the C Language
Chapter 2 - Introduction to C Programming
Documentation Need to have documentation in all programs
TMF1414 Introduction to Programming
Chapter 2 - Introduction to C Programming
Introduction to the C Language
Introduction to the C Language
Introduction to C++ Programming
Basics of ‘C’.
Chapter 2: Introduction to C++.
WEEK-2.
DATA TYPES There are four basic data types associated with variables:
C Programming Lecture-3 Keywords, Datatypes, Constants & Variables
Variables and Constants
Presentation transcript:

CSCI 3133 Programming with C Instructor: Bindra Shrestha University of Houston – Clear Lake

Chapter 2: Introduction to C Background Structure of C Programs Identifiers Data types Variables Constants

Background A structured language Allows programmer to concentrate on the problem at hand Runs on different hardware platforms-popular Derived from ALGOL Dennis Ritchie developed C

Structure of a C Programs 1. Preprocessor directives 2. Global Declarations 3. Main 4. Local Definitions 5. Statements 6. Return type

. 1. Preprocessor directives Special instructions to the preprocessor to include library systems, header files-eg. input/output library Starts with # sign, no space between # and include Preferable in the first line.h or header files 2. Global Declarations are v isible to the whole program

. 3. Main only one in the whole program eg. int main(void) {} are used ; ends each statements /* This is a comment*/ Inner comments are not allowed 4. Local Definitions definition in the function 5. Statements - instructions to the computer 6. Return type

Identifiers Allows us to name the data and other objects Valid names are capital letters, lowercase letters, digits and the underscore The first character cannot be a digit System libraries use underscore as the first character by custom. Names cannot be 30-plus special names known as reserved words-more on appendix B Good identifiers are Descriptive but short

Standard Data Types 1. void has no type, plays the role of generic type 2. int - integer type without a fraction, can be short int, int,long int. Integer data type can be divided into signed or unsigned types eg. Pg 33, Table char- includes any value that can be represented in the computer’s alphabet (ASCII), normally size is 1 byte Difference between a and x? and float is a number with fractional part,can be float double, and long double, is always signed type pg35, table 2-5

Logical Data Type Boolean can represent only two values, referred to as true and false or on/off C supports logical type through the integer type, any nonzero represent true and zero represent false

Variables Variable are named memory locations that have a type They can be changed or manipulated Each variable must be declared and defined They are used to hold the data required by the program for its operation. Its type can be char, int, and float but not void eg char a, int i, float tax. See pg 36, fig2-9, pg 37, Table2-7

Variable Initialization Variable can also be initialized at the time of declaration Must be defined before using them Initializer establishes the first value that the variable will contain int number, sum=0; int number; int sum; They are not initialized automatically

Constants Constants are data types that cannot be changed during the execution of a program Examples, pg 39 Table 2-8 int eg. 123 long int eg. 32,271L unsigned long int eg. 76,542LU Default is signed integer or long signed integer

Float Constants They are numbers with decimal parts. Default form is double double 2.5 long double L

Character Constants Character constants are enclosed between single quotes Backslash is the escape character is used when it cannot be entered from keyboard Example of character set are: null character ‘\0’ alert(bell) ‘\a’ newline ‘\n’ Table 2-10

. String Constants: is a sequence of zero or more characters enclosed in double quotes “ “hello\n” “WELCOME!” “” is an empty string while ‘\0’ is a null character

Coding Constants Literal Contants for eg, 5, a, “hello world”, a+5 Defined Constants #define SALESTAX.0825 Memory Constants Memory constants use a type qualifier eg. const float PI = 3.14

Formatted Input/Output Input reads formatted data from keyboard The keyboard is called Standard input file Output The monitor is called Standard output file The keyboard input is usually buffered, ie a temporary storage area holds inputs until one complete line has been recieved

The standard output function is printf The standard input function is scanf printf needs two things: instructions for formatting data and the actual data to be printed. Format string is coded like (“…”) printf (“%d\n%d”, a,b) Conversion codes are: character ( c ), integer(d), and floating poing ( f )