Ch 4 - 1 Chapter 4 Basic Data Types and Variables 4.1 Basic Data Types In C TABLE 4.1 Introduction to Basic Data Types in C Type SizeDescription char 1.

Slides:



Advertisements
Similar presentations
Chapter 3 DATA: TYPES, CLASSES, AND OBJECTS. Chapter 3 Data Abstraction Abstract data types allow you to work with data without concern for how the data.
Advertisements

Enumeration Data Type enum Day {SUN, MON, TUE, WED, THU, FRI, SAT}; Day today; today = WED; if (today == FRI) cout
Neal Stublen C# Data Types Built-in Types  Integer Types byte, sbyte, short, ushort, int, uint, long, ulong  Floating Point Types.
Principles of Programming Fundamental of C Programming Language and Basic Input/Output Function 1.
1 Types The type of a variable represents a set of values that may be assigned to the variable. For example, an integer variable is one that may take the.
Structure of a C program
CS1061 C Programming Lecture 4: Indentifiers and Integers A.O’Riordan, 2004.
Data types and variables
Chapter 2 Data Types, Declarations, and Displays
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the structure of a C-language program. ❏ To write your first C.
Variables and constants Applications of Computer Programming in Earth Sciences Instructor: Dr. Cheng-Chien LiuCheng-Chien Liu Department of Earth Sciences.
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
Chapter 2: C Fundamentals Dr. Ameer Ali. Overview C Character set Identifiers and Keywords Data Types Constants Variables and Arrays Declarations Expressions.
CSCI 1100/1202 January 16, Why do we need variables? To store intermediate results in a long computation. To store a value that is used more than.
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
CSC 107 – Programming For Science. Announcements  Textbook available from library’s closed reserve.
C Tokens Identifiers Keywords Constants Operators Special symbols.
C-Language Keywords(C99)
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.
PHY 107 – Programming For Science. Announcements  Slides, activities, & solutions always posted to D2L  Note-taking versions before class, for those.
Lesson 3 – Primitive Data Types Objective: Students will investigate the definition and usage of objects and primitive data types in Java in order to practice.
1.Identifiers 2.Variables 3.Keywords 4.Statements 5.Comments 6.Whitespaces 7.Syntax 8.Semantic © In this session we will.
Simple Data Types Built-In and User Defined Chapter 10.
The character data type char. Character type char is used to represent alpha-numerical information (characters) inside the computer uses 2 bytes of memory.
CONSTANTS Constants are also known as literals in C. Constants are quantities whose values do not change during program execution. There are two types.
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.
Data Structure and c K.S.Prabhu Lecturer All Deaf Educational Technology.
CSCI 3133 Programming with C Instructor: Bindra Shrestha University of Houston – Clear Lake.
Enumeration.
Java Programming, Second Edition Chapter Two Using Data Within a Program.
Chapter 7 C supports two fundamentally different kinds of numeric types: (a) integer types - whole numbers (1) signed (2) unsigned (b) floating types –
Chapter2 Constants, Variables, and Data Types. 2.1 Introduction In this chapter, we will discuss –constants (integer, real, character, string, enum),symbolic.
USER INTERACTION AND VARIABLES Tarik Booker CS 290 California State University, Los Angeles.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
Introduction to ‘c’ language
User Interaction and Variables
Variables Mr. Crone.
Introduction to the C Language
Wel come.
ITEC113 Algorithms and Programming Techniques
សាកលវិទ្យាល័យជាតិគ្រប់គ្រង National University of Management
By: Syed Shahrukh Haider
Variables ,Data Types and Constants
DATA HANDLING.
Introduction to the C Language
Variables In programming, we often need to have places to store data. These receptacles are called variables. They are called that because they can change.
פרטים נוספים בסילבוס של הקורס
MON TUE WED THU
C AS A LANGUAGE Interface between computer & human being. ALPHABETS
Chapter 2: Java Fundamentals
Presenting information as bit patterns
2008 Calendar.
Chapter 2: Java Fundamentals
Sun Mon Tue Wed Thu Fri Sat
Learning Intention I will learn how computers store text.
Sun Mon Tue Wed Thu Fri Sat
Introduction to Programming
Module 2 Variables, Data Types and Arithmetic
1/○~1/○ weekly schedule MON TUE WED THU FRI SAT SUN MEMO
2016 | 10 OCT SUN MON TUE WED THU FRI SAT
C Language B. DHIVYA 17PCA140 II MCA.
Sun Mon Tue Wed Thu Fri Sat
EECE.2160 ECE Application Programming
WEB PAGES: Tables Welcome Back !.
C Programming Lecture-3 Keywords, Datatypes, Constants & Variables
Variables and Constants
2008 Calendar.
Presentation transcript:

Ch Chapter 4 Basic Data Types and Variables 4.1 Basic Data Types In C TABLE 4.1 Introduction to Basic Data Types in C Type SizeDescription char 1 byte Characters or small integer variables int 2 or 4 bytes Integer values float 4 bytes Floating point numbers double 8 bytes Floating point numbers

Ch CHARACTERS The Standard for Text: ASCII(American Standard Code for Information Interchange) was first defined by the American National Standards Institute in In this code, each letter of the alphabet, punctuation mark, and decimal number is assigned a unique 7-bit code number. With 7 bits, 128 unique symbols can be coded. See Table 4.2.

Ch TABLE 4.2 ASCII Character Format

Ch Defining Character Variables in C Program 4.1: C Program Containing Variables int main ( void ) { /* Beginning of the (main) block.*/ Char cAChar;/* We put variable definitions here.*/ cAChar = 65 ;/* Executable statement : assign the */ /* code for ‘A’ to “cAChar”*/ }/* End of (main) block */

Ch Character Constants cAChar = ‘A’ ;/*assign ‘A’ to character */ /* variable “cAChar” */

Ch Escape Characters

Ch Remark 4.2

Ch INTEGERS Consider for example the declarations int iPennies; int iCounter; Initial Values can also be supplied in definitions, as with int iCounter = 0; int iNickels = 5;

Ch Short and Long Integers short<=int<=long

Ch Unsigned Integers Ex: unsigned int uiPennies; unsigned uUpCounter;

Ch SINGLE AND DOUBLE PRECISION FLOATING POINT NUMBERS

Ch Floating Point Variables Floating point variables and constants: 3.4,-45.33,2.714, Exponential notation: 3.0e-25,4.5e+05, e+19,

Ch Figure 4.2

Ch Table 4.5

Ch Program 4.2 : Print size of some basic data types

Ch 接續 Program 4.2

Ch ENUMERATION DATA TYPES enum weekday { Mon, Tue, Wed, Thu, Fri, Sat, Sun }; or enum dayofweek { Mon=1, Tue, Wed, Thu, Fri, Sat, Sun }; Program 4.3

Ch

Ch VARIABLE ATTRIBUTES: TYPE, ADDRESS, NAME, AND VALUE int iVal = 10; Type Name Value

Ch Program 4.4

Ch

Ch VARIABLE NAMING CONVENTIONS A variable name cannot start with a digit, and it cannot have the same as a reserved word.

Ch An appropriate name name for our count variable: int iCount ; unsigned int uiCount ; unsigned uCount;

Ch