Variables and Data Types.  Variable: Portion of memory for storing a determined value.  Could be numerical, could be character or sequence of characters.

Slides:



Advertisements
Similar presentations
Lecture Computer Science I - Martin Hardwick The Programming Process rUse an editor to create a program file (source file). l contains the text of.
Advertisements

C++ Basics Variables, Identifiers, Assignments, Input/Output.
Computer Programming Basics Assistant Professor Jeon, Seokhee Assistant Professor Department of Computer Engineering, Kyung Hee University, Korea.
Dale/Weems/Headington
IntroductionIntroduction  Computer program: an ordered sequence of statements whose objective is to accomplish a task.  Programming: process of planning.
Structure of a C program
C Programming Basics Lecture 5 Engineering H192 Winter 2005 Lecture 05
1 9/8/08CS150 Introduction to Computer Science 1 Data Types Section 2.7 – 2.12 CS 150 Introduction to Computer Science I.
J. P. Cohoon and J. W. Davidson © 1999 McGraw-Hill, Inc. The Fundamentals of C++ Basic programming elements and concepts.
SECTION 2 C++ Language Basics. Strategies for learning C++ Focus on concepts and programming techniques. (Don’t get lost in language features) Learn C++
CS1061 C Programming Lecture 4: Indentifiers and Integers A.O’Riordan, 2004.
CS150 Introduction to Computer Science 1
Data Types.
Basic Elements of C++ Chapter 2.
KEAN UNIVERSITY Visual C++ Dr. K. Shahrabi. Developer studio Is a self-contain environment for creating, compiling, linking and testing windows program.
CS 192 Lecture 3 Winter 2003 December 5, 2003 Dr. Shafay Shamail.
© Janice Regan, CMPT 128, Jan CMPT 128: Introduction to Computing Science for Engineering Students Data representation and Data Types Variables.
COMPUTER PROGRAMMING. Data Types “Hello world” program Does it do a useful work? Writing several lines of code. Compiling the program. Executing the program.
1 Identifiers  Identifiers are the words a programmer uses in a program  An identifier can be made up of letters, digits, the underscore character (
CS 161 Introduction to Programming and Problem Solving Chapter Hello World Program in C++ And Lexical Rules Herbert G. Mayer, PSU Status 10/18/2014.
C Tokens Identifiers Keywords Constants Operators Special symbols.
C-Language Keywords(C99)
 Programming Languages  First Generation Languages (Machine Language)  We Actually have to do a few things. First we have to find the operating code,
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
1 More C++ Basics Chapter 3 Lecture CSIS 10A. 2 Agenda Review  C++ Standard Numeric Types Arithmetic–way more than you want! Character (char) data type.
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
C++ Programming, Namiq Sultan1 Chapter 2 Introduction to C++ Namiq Sultan University of Duhok Department of Electrical and Computer Engineerin Reference:
COMPUTER PROGRAMMING. variable What is variable? a portion of memory to store a determined value. Each variable needs an identifier that distinguishes.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 5P. 1Winter Quarter C Programming Basics.
SE-1010 Dr. Mark L. Hornick 1 Variables & Datatypes.
Computing with C# and the.NET Framework Chapter 2 C# Programming Basics ©2003, 2011 Art Gittleman.
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 5P. 1Winter Quarter C Programming Basics Lecture 5.
Data Structure and c K.S.Prabhu Lecturer All Deaf Educational Technology.
Data Types, Primitive Types in C++, Variables – Declaration, Initialization, Scope Telerik Software Academy academy.telerik.com Learning and Development.
C++ Basics Programming. COMP104 Lecture 5 / Slide 2 Introduction to C++ l C is a programming language developed in the 1970s with the UNIX operating system.
Variables in C Topics  Naming Variables  Declaring Variables  Using Variables  The Assignment Statement Reading  Sections
1 CSC 1111 Introduction to Computing using C++ C++ Basics (Part 1)
CMSC 104, Version 8/061L09VariablesInC.ppt Variables in C Topics Naming Variables Declaring Variables Using Variables The Assignment Statement Reading.
Basic Types, Variables, Literals, Constants. What is in a Word? A byte is the basic addressable unit of memory in RAM Typically it is 8 bits (octet)
C++ Lesson 1.
Asst.Prof.Dr. Tayfun ÖZGÜR
Variables, Identifiers, Assignments, Input/Output
Chapter 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
Basics (Variables, Assignments, I/O)
Chapter 1.2 Introduction to C++ Programming
Data types Data types Basic types
LESSON 3 IO, Variables and Operators
Compiler Construction
Computing with C# and the .NET Framework
بسم الله الرحمن الرحيم.
Reserved Words.
Chapter 2.
Basics (Variables, Assignments, I/O)
null, true, and false are also reserved.
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.
פרטים נוספים בסילבוס של הקורס
Introduction to Java Programming
درس برنامه‌سازي کامپيوتر
Basics of ‘C’.
פרטים נוספים בסילבוס של הקורס
Keywords.
Variables, Identifiers, Assignments, Input/Output
Prof. Bhushan Trivedi Director GLS Institute of Computer Technology
Variables in C Declaring , Naming, and Using Variables.
2. Second Step for Learning C++ Programming • Data Type • Char • Float
Programming Language C Language.
Module 2 - Part 1 Variables, Assignment, and Data Types
Presentation transcript:

Variables and Data Types

 Variable: Portion of memory for storing a determined value.  Could be numerical, could be character or sequence of characters called strings  Variable examples: 20, “California”, ‘a’ etc…

 Valid Identifier: Used to identify a particular variable in the memory. Like a reference.  Sequence of one or more letters, digits or one underscore character.  Cannot start with number  Best practice is to start with a letter.  Examples: myValue, _num, num2 etc…

 Cannot use words like: asm, auto, bool, break, case, catch, char, class, const, const_cast, continue, default, delete, do, double, dynamic_cast, else, enum, explicit, export, extern, false, float, for, friend, goto, if, inline, int, long, mutable, namespace, new, operator, private, protected, public, register, reinterpret_cast, return, short, signed, sizeof, static, static_cast, struct, switch, template, this, throw, true, try, typedef, typeid, typename, union, unsigned, using, virtual, void, volatile, wchar_t, while  Or, cannot use and, and_eq, bitand, bitor, compl, not, not_eq, or, or_eq, xor, xor_eq

 C++ is case sensative  Name identifier like abc is not same as Abc or ABC. They are identified completely differently

 Computer needs to know what kind of data we are storing in case we will have to process those data later on for other purposes.  Fundamental data types:  char : Character or small integer, size=1 byte  short int(short) : short integer, size: 2 bytes  int: Integer, size: 4bytes  long int(long): long integer 4bytes  bool: Boolean value(true or false, 1 or 0), size: 1byte  float: decimal number, size: 4 bytes  double: double precision floating point number, size: 8 bytes  long double: size: 8bytes  wchat_t : Wide character, size: 2 or 4 bytes

 int a;  identifier is a, data type is integer  float b;  identifier is b, data type is b;  double num;  identifier is num, data type is double  int a, b, c;  3 integer variables named a, b, c  Same as int a;  int b;  int c;

 Signed: can have both positive and negative numbers  Unsigned: Only positive numbers  Example: signed int a; unsigned int b;  Default is signed in c++ so if nothing is given it takes it as signed. Example int a; is signed integer a.

#include using namespace std; int main() { int a, b; int sum; a=23; b=56; sum=a+b; cout << sum; return 0; }

 Variable needs to be declare first to be initialized.  int a;  is declaring variable, saying that make a new variable named a which is an integer  a = 23;  Initializing variable a and giving value 23 to a;  In c++ both can happen in same line  Example int a = 23;  First initialized int a( = 23;)  Then initialized int ( a = 23; )

 Can be initialized in two ways:  int a = 23;  Or  int a(23);

#include using namespace std; int main() { int a = 23; int b(56); int sum; sum=a+b; cout << sum; return 0; }

 Need to add #include to start the program  String: sequence of characters  Declaring string same as other variables except changing data type to string  Example: string myname;  Value of string data type always needs to be inside “ ”.  Example myname = “Dean”;  While declaring characters they should be given inside single quotes:  Example: char myChar=‘a’;  Character takes only one character while string is collection of character in one variable identifier

#include using namespace std; int main() { string MyName = “My name is Dean”; cout << MyName << endl; string AnotherString = “Jones”; string AddedString = MyName+AnotherString; cout << AddedString << endl; } Important!!! String Concatination (Adding two strings)

 Next Video: Constants  Then: Operators  Following with: Basic input and output to end the basics!!!