User Interaction and Variables

Slides:



Advertisements
Similar presentations
Variables in C Amir Haider Lecturer.
Advertisements

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.
Primitive Data Types There are a number of common objects we encounter and are treated specially by almost any programming language These are called basic.
Structure of a C program
Introduction to C Programming Overview of C Hello World program Unix environment C programming basics.
CS1061 C Programming Lecture 4: Indentifiers and Integers A.O’Riordan, 2004.
1 Key Concepts:  Data types in C.  What is a variable?  Variable Declaration  Variable Initialization  Printf()  Scanf()  Working with numbers in.
CS150 Introduction to Computer Science 1
1 Agenda Variables (Review) Example Input / Output Arithmetic Operations Casting Char as a Number (if time allow)
Data Types.
Lecture No: 16. The scanf() function In C programming language, the scanf() function is used to read information from standard input device (keyboard).
Programming Variables. Named area in the computer memory, intended to contain values of a certain kind (integers, real numbers, characters etc.) They.
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.
CSC 107 – Programming For Science. Announcements  Textbook available from library’s closed reserve.
C programming for Engineers Lcc compiler – a free C compiler available on the web. Some instructions.
C Tokens Identifiers Keywords Constants Operators Special symbols.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
UniMAP Sem1-07/08EKT120: Computer Programming1 Week2.
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
Primitive Variables.
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.
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.
CSCI 3133 Programming with C Instructor: Bindra Shrestha University of Houston – Clear Lake.
Chapter 7 C supports two fundamentally different kinds of numeric types: (a) integer types - whole numbers (1) signed (2) unsigned (b) floating types –
1 09/03/04CS150 Introduction to Computer Science 1 What Data Do We Have.
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.
C Building Block Chapter 2. Variables A variable is a space in the computer’s memory set aside for a certain kind of data and given a name for easy reference.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
Tarik Booker CS 290 California State University, Los Angeles.
CS 201 Lecture 2: Elementary Programming Tarik Booker CS 201 California State University, Los Angeles.
USER INTERACTION AND VARIABLES Tarik Booker CS 290 California State University, Los Angeles.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
I F S TATEMENTS 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.
Fundamentals 2.
CIS3931 – Intro to JAVA Lecture Note Set 2 17-May-05.
Exercise 1 – Datentypen & Variablen
Input/output.
Variables A variable is a placeholder for a value. It is a named memory location where that value is stored. Use the name of a variable to access or update.
Introduction to Python Data Types and Variables
Revision Lecture
Chapter 2 Overview of C.
Variable Symbol represents a place to store information
By: Syed Shahrukh Haider
DATA HANDLING.
IDENTIFIERS CSC 111.
2008/10/01: Lecture 8 CMSC 104, Section 0101 John Y. Park
CMSC 104, Section 4 Richard Chang
Introduction to CS Your First C Programs
Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Character Set Uppercase Alphabets A,
Variables in C Topics Naming Variables Declaring Variables
Chapter 2: Java Fundamentals
Variables in C Topics Naming Variables Declaring Variables
UMBC CMSC 104 – Section 01, Fall 2016
Variables T.Najah Al_Subaie Kingdom of Saudi Arabia
Variables in C Declaring , Naming, and Using Variables.
Chapter 2: Java Fundamentals
Introduction to C Programming
C Data Types and Variable
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
Data Types and Arithmetic in C
Presentation transcript:

User Interaction and Variables Tarik Booker CS 242 California State University, Los Angeles

What we will cover… Review Data Types Standard Input

Variables Can store values to be used (later) in a program Values can be changed Remember algebra: x + y = 34 y = 5 x =? Similar Concept in Programming

Variables (2) You must declare a variable in a program before you use it Format: datatype variableName; A variable can be of any name Follow identifier rules (later…) Descriptive names are best

Variables (3) Datatype variableName; Datatype Datatype variableName1, variableName2, …,variableName3; Datatype Specific classification of variables Different types / different memory sizes int, double (main ones) Discuss later

Variables (4) Variables are Case-Sensitive in C Uppercase and Lowercase Not the Same “Variable1” is not the same as “variable1”

Identifiers To name variables or functions Called identifiers Should obey rules: Consists of letters (upper/lower), digits, underscores Must start with a letter (alphabetic character) Must NOT start with a digit!!! Cannot be a reserved word (int, return, main, etc.) Can be up to 31 characters

Identifiers (2) Which are legal? helloworld aadzxvcna343546390thjke456hftg3sd HappyHappy 34joy56 $Dollarsand return mains #love Why / Why not?

Char There is another type of variable other than integers or floating-point Char Allows you to store a single character Uses ASCII American Standard Code for Information Interchange Each character is assigned to a particular number ASCII Table ‘A’ is 65 ‘a’ is 97 Lowercase is higher than Uppercase Add 32 to change an uppercase letter to lowercase Subtract 32 to change a lowercase letter to uppercase

ASCII Table

Reading in a Value from Standard In Before, we used a function to send information to Standard out What was it? Now we can get information from Standard in Let’s get a character from standard in Use the scanf() function

Scanf A way to input data into the computer is to use scanf This can “scan” in characters from the console Format similar to printf int x; scanf(“%d”, &x); This puts the value of %d into x Different types for % (called format specifiers) %d = decimal (integer) %c = character We will talk about others later…

Scanf (2) Note the & sign before the x int x; scanf(“%d”, &x); This is a pointer reference Outside the scope of this class Passes to scanf the memory address of the variable x Keep the same format – don’t worry about pointers

Data Types Char is considered a data type A data type is just the way information is stored in the program char, int, float, double, void (will discuss) are called primitive data types or primitives Other types of primitive data types

Data Types Char Character Int Integer Double Double Precision Floating-Point Void no type (or empty) Void Use this data type when no type is expected Primarily used for functions to specify not a return type Look at main

Data Types (2) C has many many different types of basic (or primitive) data types Different versions of char, int, long, double Char Signed char uses signed version of char Unsigned char uses unsigned version of char

Data Types (3) Short 16-bit integer type Short int Signed short Signed short int Unsigned short Unsigned short int

Data types (4) Int Signed int Unsigned Unsigned int Long long integer (at least 32 bits) Long int Signed long Signed long int Unsigned long Unsigned long int

Data types (5) Long long 64-bit integer Long long int Signed long long Signed long long int

Data Types (6) Float Double Long double There are also other types: Boolean (next week) True/False

We will do in class work today! Let’s do some problems!