Lecture 4 Monday Sept 9, 2002. Variables and Data Types ►A►A►A►A variable is simply a name given by the programmer that is used to refer to computer storage.

Slides:



Advertisements
Similar presentations
Variables in C Amir Haider Lecturer.
Advertisements

1 9/10/07CS150 Introduction to Computer Science 1 Data Types Section 2.7 – 2.12 CS 150 Introduction to Computer Science I.
Structure of a C program
CS1061 C Programming Lecture 4: Indentifiers and Integers A.O’Riordan, 2004.
Data types and variables
CS150 Introduction to Computer Science 1
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.
Objectives You should be able to describe: Data Types
Chapter 2: C Fundamentals Dr. Ameer Ali. Overview C Character set Identifiers and Keywords Data Types Constants Variables and Arrays Declarations Expressions.
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.
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.
Primitive Variables.
Course Title: Object Oriented Programming with C++ instructor ADEEL ANJUM Chapter No: 03 Conditional statement 1 BY ADEEL ANJUM (MSc-cs, CCNA,WEB DEVELOPER)
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals. Procedural Constructs.
BASICS CONCEPTS OF ‘C’.  C Character Set C Character Set  Tokens in C Tokens in C  Constants Constants  Variables Variables  Global Variables Global.
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.
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.
Programming Fundamentals. Overview of Previous Lecture Phases of C++ Environment Program statement Vs Preprocessor directive Whitespaces Comments.
CPS120: Introduction to Computer Science Variables and Constants.
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
CMSC 104, Version 8/061L09VariablesInC.ppt Variables in C Topics Naming Variables Declaring Variables Using Variables The Assignment Statement Reading.
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.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
Constants, Data Types and Variables
Numbers in ‘C’ Two general categories: Integers Floats
User Interaction and Variables
BASIC ELEMENTS OF A COMPUTER PROGRAM
ECE Application Programming
ITEC113 Algorithms and Programming Techniques
EPSII 59:006 Spring 2004.
CMSC 104, Section 4 Richard Chang
CSE101-Lec#3 Components of C Identifiers and Keywords Data types.
Variables ,Data Types and Constants
Introduction to the C Language
Tejalal Choudhary “Computer Programming” Fundamentals of “C”
2008/10/01: Lecture 8 CMSC 104, Section 0101 John Y. Park
CMSC 104, Section 4 Richard Chang
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.
Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Character Set Uppercase Alphabets A,
C++ Basics.
2.1 Parts of a C++ Program.
פרטים נוספים בסילבוס של הקורס
Variables in C Topics Naming Variables Declaring Variables
Basics of ‘C’.
CS111 Computer Programming
C++ Data Types Data Type
Variables in C Topics Naming Variables Declaring Variables
Variables in C Declaring , Naming, and Using Variables.
Chapter 2: Introduction to C++.
WEEK-2.
C++ Programming Lecture 3 C++ Basics – Part I
© A+ Computer Science - Variables & Data Types © A+ Computer Science - ©A+ Computer Science
Variables in C Topics Naming Variables Declaring Variables
2008/10/01: Lecture 8 CMSC 104, Section 0101 John Y. Park
C Language B. DHIVYA 17PCA140 II MCA.
Variables in C Topics Naming Variables Declaring Variables
EECE.2160 ECE Application Programming
C Programming Lecture-3 Keywords, Datatypes, Constants & Variables
Variables in C Topics Naming Variables Declaring Variables
Variables and Constants
Programming Fundamental-1
Variables in C Topics Naming Variables Declaring Variables
Presentation transcript:

Lecture 4 Monday Sept 9, 2002

Variables and Data Types ►A►A►A►A variable is simply a name given by the programmer that is used to refer to computer storage location (memory). ►T►T►T►The term variable is used because the value stored in the variable can change. ► T► T► T► The value stored is the data. ►D►D►D►Data can be of different types.

Pictorial understanding Variables ab c a b c are variables are memory addresses are values stored or data.

Rules for Variable names & declaration ► T► T► T► The variable name must begin with a letter or underscore(_), and may contain only letters, underscores, or digits. It cannot contain any blanks, commas, or special symbols, such as () &, $ # etc… ► A► A► A► A varible name cannot be a keyword ► T► T► T► The variable name cannot consist of more than 31 characters.

Keywords ► A► A► A► A keyword is a word that is set aside by the language for a special purpose and can only be used in a specific manner. Eg : auto voidshort sizeof break switch privatefloat continueforifdelete etc……

Types of Data Data Types Integer Short intLong int Unsigned short int Unsigned long int Floatdouble Long double char Signed chatUnsigned char

Definitions ► I► I► I► Integer – A zero, or any positive or negative value without a decimal point. eg : 0, 5, -19, ► F► F► F► Float – Also called real number, any positive or negative number having a decimal point eg : , -6.3, 0.34, -6.67

Definitions contd… ►C►C►C►Char – Includes : 1. l etters of the alphabet (upper and lower case). 2. T en digits 0 thro S pecial symbols – $, !, b, A etc…. 4. A single character is any one letter, digit or special symbol enclosed within single quotes. Eg ‘ A ‘ ‘ $ ‘ ‘ b’

Char contd….. ►C►C►C►Characters are stored as ASCII or EBCDIC code. ►A►A►A►ASCII – American standard code for Information Interchange. ►E►E►E►EBCDIC – Extended Binary Coded Decimal Interchange Code. ►E►E►E►Each code corresponds to a number between -128 to 128 if signed else 0 to 255 for unsigned.

Definitions contd… ► s► s► s► short int – represents fairly small integer values and requires half the amount of storage with respect to int. ► l► l► l► long int represents fairly large integer values and requires double the amount of storage with respect to int. ►U►U►U►Unsigned is used to increase the range in the positive side.

► d► d► d► double refers to same data type as float but with greater size and range of numbers. ► l► l► l► long double - To further increase size and range of numbers. ►N►N►N►Note: In some computers int and short int have the same storage size.

Tabular understanding ► Primary Data types Data Type Data TypeSize ( bytes) Range CharIntFloatdouble to : e38 : 3.4e e308: 1.7e308

Integer data types Data type Size (bytes) Range - Short Int or signed short int int - Unsigned short int - Int or signed int - unsigned int - Long int or signed long int int - Unsigned long int : : 65, : : : :

Floating point data types Data type Size ( bytes ) Range floatdouble Long double e38 : 3.4e e308 : 1.7e e308 : 1.7e e4932 : 1.7e4932

Character data types Data type Size ( bytes ) Range Char or signed char Unsigned char : : 255

sizeof operator ► D► D► D► Different machines give different storage size for the data types. ►T►T►T►The previously quoted sizes and range are for the MS-DOS environment. ►T►T►T►The sizeof operator is used to find the storage size of data types of the computer under use. ►T►T►T►The info got from this operator can be very useful when transferring a program to a different computer.

sizeof operator contd ► Usage ExpressionResult sizeof(char)sizeof(int)sizeof(float)sizeof(double)1248

Problem # 3 ► T► T► T► To find storage size of a data type ? #include<iostream.h> // preprocessor directive void main() // function main { int a =3, ss; // Variable declaration part ss=sizeof(a); // find size of int a cout<<“The size of int a is ”<<ss<<endl; cout<<“the value of a is ”<<a<<endl; }