ASST. Prof. Dr. Hacer Yalım Keleş

Slides:



Advertisements
Similar presentations
IntroductionIntroduction  Computer program: an ordered sequence of statements whose objective is to accomplish a task.  Programming: process of planning.
Advertisements

1 9/10/07CS150 Introduction to Computer Science 1 Data Types Section 2.7 – 2.12 CS 150 Introduction to Computer Science I.
1 Lecture 2  Input-Process-Output  The Hello-world program  A Feet-to-inches program  Variables, expressions, assignments & initialization  printf()
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?
CS150 Introduction to Computer Science 1
Basic Elements of C++ Chapter 2.
C Programming. Chapter – 1 Introduction Study Book for one month – 25% Learning rate Use Compiler for one month – 60%
Programming Languages
Chapter 2: C Fundamentals Dr. Ameer Ali. Overview C Character set Identifiers and Keywords Data Types Constants Variables and Arrays Declarations Expressions.
C Programming Lecture 4 : Variables , Data Types
C Tokens Identifiers Keywords Constants Operators Special symbols.
Sales person receive RM200/week plus 9% of their gross sales for that week. Write an algorithms to calculate the sales person’s earning from the input.
 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.
Lecture 1 cis208 January 14 rd, Compiling %> gcc helloworld.c returns a.out %> gcc –o helloworld helloworld.c returns helloworld.
DATA TYPE AND DISPLAY Computer Programming Asst. Prof. Dr. Choopan Rattanapoka and Asst. Prof. Dr. Suphot Chunwiphat.
Chapter 3 – Variables and Arithmetic Operations. Variable Rules u Must declare all variable names –List name and type u Keep length to 31 characters –Older.
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Input and Output.
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.
1 Lexical Elements, Operators, and the C System. 2 Outline Characters and Lexical Elements Syntax Rules Comments Keywords Identifiers Constants String.
Silberschatz and Galvin  C Programming Language Kingdom of Saudi Arabia Ministry of Higher Education Al-Majma’ah University College of Education.
Java Programming: From Problem Analysis to Program Design, Second Edition 1 Lecture 1 Objectives  Become familiar with the basic components of a Java.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
C is a high level language (HLL)
Java Basics. Tokens: 1.Keywords int test12 = 10, i; int TEst12 = 20; Int keyword is used to declare integer variables All Key words are lower case java.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
BIL 104E Introduction to Scientific and Engineering Computing Lecture 2.
1 ENERGY 211 / CME 211 Lecture 3 September 26, 2008.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
Introduction to ‘c’ language
Chapter Topics The Basics of a C++ Program Data Types
The Machine Model Memory
BASIC ELEMENTS OF A COMPUTER PROGRAM
Chap. 2. Types, Operators, and Expressions
ECE Application Programming
Tokens in C Keywords Identifiers Constants
ITEC113 Algorithms and Programming Techniques
Basic Elements of C++.
Revision Lecture
Lecture2.
What to bring: iCard, pens/pencils (They provide the scratch paper)
Introduction to C Programming
CSE101-Lec#3 Components of C Identifiers and Keywords Data types.
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.
Basic Elements of C++ Chapter 2.
2008/10/01: Lecture 8 CMSC 104, Section 0101 John Y. Park
Number Representations
C++ Basics.
An overview of Java, Data types and variables
Beginning C Lecture 2 Lecturer: Dr. Zhao Qinpei
Introduction to C Programming
Variables in C Topics Naming Variables Declaring Variables
Lectures on Numerical Methods
Introduction C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell.
Introduction to C++ Programming
C++ Programming Lecture 3 C++ Basics – Part I
ECE 103 Engineering Programming Chapter 8 Data Types and Constants
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
Programming Languages and Paradigms
Lexical Elements & Operators
2008/10/01: Lecture 8 CMSC 104, Section 0101 John Y. Park
DATA TYPES There are four basic data types associated with variables:
C Language B. DHIVYA 17PCA140 II MCA.
EECE.2160 ECE Application Programming
Introduction to C Programming
Variables in C Topics Naming Variables Declaring Variables
Number Representations
ECE 120 Midterm 1 HKN Review Session.
Presentation transcript:

ASST. Prof. Dr. Hacer Yalım Keleş COM101B Lecture 1: BASICS ASST. Prof. Dr. Hacer Yalım Keleş Reference: “Programming in ANSI C”, Kumar & Agrawal, West Publishing Co., 1992

The sequentıal structure Entry -> Statement 1 -> Statement 2 -> ... -> Statement N -> Exit Example Program: #include <stdio.h> int main() { printf(«Knowledge is power\n»); return 0; } Reference: “Programming in ANSI C”, Kumar & Agrawal, West Publishing Co., 1992

CHARACTER SET The set of characters that may appear in legal C programs is called the «character set» for a language. This may include graphic and non-graphic characters Graphic characters: that may be printed Non-graphic characters: represented by escape sequences, i.e. \n, \t, etc. There is also a null character: \0 Reference: “Programming in ANSI C”, Kumar & Agrawal, West Publishing Co., 1992

Reference: “Programming in ANSI C”, Kumar & Agrawal, West Publishing Co., 1992

C compiler groups characters into tokens: The graphic characters, other than decimal digits, letters and blank are called special characters Blank, horizontal and vertical tabs, newlines and formfeeds are called whitespace characters C compiler groups characters into tokens: A token is a sequence of one or more characters that have a uniform meaning Some tokens are one char long, i.e. /,*,+,> etc. Some tokens are sevaral char long, i.e. ==, >=, comments, variable names etc. When collecting characters into tokens, the compiler always performs the longest possible tokens. Reference: “Programming in ANSI C”, Kumar & Agrawal, West Publishing Co., 1992

C is a free-format language: tokens can go anywhere on a page Tokens can be separated by any number of whitespaces. The program below: int main() { printf(«Hello»); } Is equivalent to: int main(){printf(«Hello»); } Reference: “Programming in ANSI C”, Kumar & Agrawal, West Publishing Co., 1992

Data types Data is differentiated into types: Built-in data types: The type of a data element restricts the set of values that the data element can take. Built-in data types: char: a character in the C character set int: an integer float: a single-precision floating point number double: a double-precision floating point number Some extensions: short int, long int, long double Reference: “Programming in ANSI C”, Kumar & Agrawal, West Publishing Co., 1992

The qualifiers signed and unsigned can be applied to: char, short int, int, or long int. unsigned variables: can only have non-negative values. signed variables: can have both positive and negative values. In the absence of explicit usigned specification; int, long int, or short int are considered as signed. Reference: “Programming in ANSI C”, Kumar & Agrawal, West Publishing Co., 1992

SIGNED REPRESENTATIONS Ones’ Complement Representation (8 bits): Binary value Ones’ Complement Interp. Unsigned Interpret. 00000000 +0 0 00000001 1 1 ... ... ... 01111111 127 127 10000000 -127 128 10000001 -126 129 11111110 -1 254 11111111 -0 255 Reference: “Programming in ANSI C”, Kumar & Agrawal, West Publishing Co., 1992

SIGNED REPRESENTATIONS Two’s Complement Representation (8 bits): Binary value Two’s Complement Interp. Unsigned Interpret. 00000000 0 0 00000001 1 1 ... ... ... 01111111 127 127 10000000 -128 128 10000001 -127 129 11111110 -2 254 11111111 -1 255 Reference: “Programming in ANSI C”, Kumar & Agrawal, West Publishing Co., 1992

The widths of the datatypes are not specified by the C language, yet many implementations represent a char in 8 bits, a short in 16 bits, an int in 16 or 32 bits, a long in 32 bits C specifies that: the range of int may not be smaller than short, the range of long may not be smaller than int, the long double is at least as precise as a double a double at least as precise as a float The particular bit widths of an implementation are specified in: <limits.h> and <float.h> header files. Reference: “Programming in ANSI C”, Kumar & Agrawal, West Publishing Co., 1992

Types cntd. Integral types: Floating-point types: Arithmetic types: all types of integers and characters Floating-point types: float, double, long double Arithmetic types: Integral and floating point types Reference: “Programming in ANSI C”, Kumar & Agrawal, West Publishing Co., 1992