CSCI 130 Chapter 3. Variables & Names Variable Declarations: –reserve a storage location in memory –identify the name of the variable –identify the type.

Slides:



Advertisements
Similar presentations
Variables in C Amir Haider Lecturer.
Advertisements

Etter/Ingber Engineering Problem Solving with C Fundamental Concepts Chapter 2 Simple C Programs.
Chapter 3: Beginning Problem Solving Concepts for the Computer Programming Computer Programming Skills /1436 Department of Computer Science.
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
CS150 Introduction to Computer Science 1
Variables and constants Applications of Computer Programming in Earth Sciences Instructor: Dr. Cheng-Chien LiuCheng-Chien Liu Department of Earth Sciences.
Basic Elements of C++ Chapter 2.
ECE 103 Engineering Programming Chapter 10 Variables, AKA Objects Herbert G. Mayer, PSU CS Status 6/19/2015 Initial content copied verbatim from ECE 103.
COMPUTER PROGRAMMING. Data Types “Hello world” program Does it do a useful work? Writing several lines of code. Compiling the program. Executing the program.
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.
C Programming Lecture 4 : Variables , Data Types
C Tokens Identifiers Keywords Constants Operators Special symbols.
Lecture 2 Introduction to Computer Programming CUIT A.M. Gamundani Presentation Layout Data types.
CPS120: Introduction to Computer Science Variables and Constants Lecture 8 - B.
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.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
CPS120: Introduction to Computer Science
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
Course Title: Object Oriented Programming with C++ instructor ADEEL ANJUM Chapter No: 03 Conditional statement 1 BY ADEEL ANJUM (MSc-cs, CCNA,WEB DEVELOPER)
CSCI 171 Presentation 2. Program Components main() #include Variable Definition Function Prototype Program Statements Function Call Function Definition.
BASICS CONCEPTS OF ‘C’.  C Character Set C Character Set  Tokens in C Tokens in C  Constants Constants  Variables Variables  Global Variables Global.
Introduction to Programming
VARIABLES, CONSTANTS, OPERATORS ANS EXPRESSION
CONSTANTS Constants are also known as literals in C. Constants are quantities whose values do not change during program execution. There are two types.
VARIABLES AND DATA TYPES Chapter2:part1 1. Objectives: By the end of this section you should: Understand what the variables are and why they are used.
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.
Lecture 3 Introduction to Computer Programming CUIT A.M. Gamundani Presentation Layout from Lecture 1 Background.
Variables and Constants Objectives F To understand Identifiers, Variables, and Constants.
1 09/03/04CS150 Introduction to Computer Science 1 What Data Do We Have.
Values, Types, and Variables. Values Data Information Numbers Text Pretty much anything.
Chapter 2. Variable and Data type
CMSC 1041 Variables in C Declaring, Naming, Using Variables.
Variables in C Topics  Naming Variables  Declaring Variables  Using Variables  The Assignment Statement Reading  Sections
Variables in C Topics  Naming Variables  Declaring Variables  Using Variables  The Assignment Statement Reading  Sections
CMSC 104, Version 8/061L09VariablesInC.ppt Variables in C Topics Naming Variables Declaring Variables Using Variables The Assignment Statement Reading.
2. C FUNDAMENTALS. Example: Printing a Message /* Illustrates comments, strings, and the printf function */ #include int main(void) { printf("To C, or.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
C LANGUAGE UNIT 3. UNIT 3 Arrays Arrays – The concept of array – Defining arrays – Initializing arrays.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
Fundamentals 2.
Numbers in ‘C’ Two general categories: Integers Floats
Chapter Topics The Basics of a C++ Program Data Types
User Interaction and Variables
Variables Mr. Crone.
BASIC ELEMENTS OF A COMPUTER PROGRAM
Basic Elements of C++.
CMSC 104, Section 4 Richard Chang
Basic Elements of C++ Chapter 2.
Chapter 2 Elementary Programming
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.
פרטים נוספים בסילבוס של הקורס
Variables in C Topics Naming Variables Declaring Variables
פרטים נוספים בסילבוס של הקורס
C++ Data Types Data Type
Chapter 2: Java Fundamentals
Variables in C Topics Naming Variables Declaring Variables
Variables in C Declaring , Naming, and Using Variables.
Chapter 2: Java Fundamentals
WEEK-2.
Variables in C Topics Naming Variables Declaring Variables
2008/10/01: Lecture 8 CMSC 104, Section 0101 John Y. Park
Variables in C Topics Naming Variables Declaring Variables
C Programming Lecture-3 Keywords, Datatypes, Constants & Variables
Variables in C Topics Naming Variables Declaring Variables
Variables and Constants
Variables in C Topics Naming Variables Declaring Variables
Getting Started With Coding
Presentation transcript:

CSCI 130 Chapter 3

Variables & Names Variable Declarations: –reserve a storage location in memory –identify the name of the variable –identify the type of the variable Ex: int a;

Naming rules for variables Only certain characters are legal –letters, digits, underscore ( _ ) First character must be a letter –underscore allowed but not advised Case sensitive –count, Count are two different variables Cannot use keywords

Variable Types Nonnumeric –character Numeric –signed, unsigned (signed is the default) –char, integer, floating point

Ranges / Memory Allocation Each type has a range of numbers How you use the variables in the program will determine what type you use –memory usage (efficiency) –magnitude of range Ex: open VarRanges.doc

Variable Declarations Variable declaration informs compiler of: –name of variable –type of variable Must be declared before being used Form: –typename varname;

Sample Variable Declarations int counter; char x; float salaryAccumulator; signed int z;

typedef Creates new name for existing data type Does not create new type, only creates a new name (synonym) Ex: –typedef int integer; –integer thisIsAnInteger; –int thisIsAnIntegerTo;

Numeric Variables Variables need to be initialized before being used Ex 1: –int x;Sets aside storage space for x –x = 3;Stores the value 3 in x Ex 2: –int x = 3;

Symbolic Constants Created in one of 2 ways: –#define –const keyword Cannot change value –compiler error

#define #define PI 3.14 –no equals sign –no semi-colon –no variable type PI cannot be changed in program PI is a symbolic constant –area = PI * radius * radius

const const int PI = 3.14; PI is a symbolic constant Can be used in formulas –area = PI * radius * radius

printf Will print information out to the screen –printf(“Hello world”); –printf(“Hello world\n”); prints Hello World and a carriage return –printf(“The area is %f”, area); prints: The area is xxx –xxx is the value held in the variable area

scanf Will accept information from the screen –scanf(“%d”, &area) –scanf(“%f%f”, &area, &diameter)