CS1061 C Programming Lecture 4: Indentifiers and Integers A.O’Riordan, 2004.

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

Variables in C Amir Haider Lecturer.
C++ Basics Variables, Identifiers, Assignments, Input/Output.
Introduction to Computing Lecture 01: Introduction to C Introduction to Computing Lecture 01: Introduction to C Assist.Prof.Dr. Nükhet ÖZBEK Ege University.
Data Types and Expressions
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
CPS120: Introduction to Computer Science Lecture 8.
CS 192 Lecture 3 Winter 2003 December 5, 2003 Dr. Shafay Shamail.
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 (
C Tokens Identifiers Keywords Constants Operators Special symbols.
C-Language Keywords(C99)
CPS120: Introduction to Computer Science Variables and Constants Lecture 8 - B.
CPS120: Introduction to Computer Science
BASICS CONCEPTS OF ‘C’.  C Character Set C Character Set  Tokens in C Tokens in C  Constants Constants  Variables Variables  Global Variables Global.
COMPUTER PROGRAMMING. variable What is variable? a portion of memory to store a determined value. Each variable needs an identifier that distinguishes.
Variables and Data Types.  Variable: Portion of memory for storing a determined value.  Could be numerical, could be character or sequence of characters.
CONSTANTS Constants are also known as literals in C. Constants are quantities whose values do not change during program execution. There are two types.
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.
Java Language Basics By Keywords Keywords of Java are given below – abstract continue for new switch assert *** default goto * package.
Types of C Variables:  The following are some types of C variables on the basis of constants values it has. For example: ○ An integer variable can hold.
Chapter 7 C supports two fundamentally different kinds of numeric types: (a) integer types - whole numbers (1) signed (2) unsigned (b) floating types –
Gator Engineering 1 Chapter 2 C Fundamentals (Continued) Copyright © 2008 W. W. Norton & Company. All rights reserved.
Chapter2 Constants, Variables, and Data Types. 2.1 Introduction In this chapter, we will discuss –constants (integer, real, character, string, enum),symbolic.
CPS120: Introduction to Computer Science Variables and Constants.
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.
C++ Lesson 1.
Asst.Prof.Dr. Tayfun ÖZGÜR
Basics (Variables, Assignments, I/O)
Data types Data types Basic types
LESSON 3 IO, Variables and Operators
EPSII 59:006 Spring 2004.
University of Central Florida COP 3330 Object Oriented Programming
Computing with C# and the .NET Framework
CMSC 104, Section 4 Richard Chang
CSE101-Lec#3 Components of C Identifiers and Keywords Data types.
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.
Basics (Variables, Assignments, I/O)
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.
פרטים נוספים בסילבוס של הקורס
Variables in C Topics Naming Variables Declaring Variables
Basics of ‘C’.
פרטים נוספים בסילבוס של הקורס
Variables, Identifiers, Assignments, Input/Output
Variables in C Topics Naming Variables Declaring Variables
UMBC CMSC 104 – Section 01, Fall 2016
Variables in C Declaring , Naming, and Using Variables.
Chapter 2: Introduction to C++.
2. Second Step for Learning C++ Programming • Data Type • Char • Float
Programming Language C Language.
Chap 2. Identifiers, Keywords, and Types
Module 2 Variables, Data Types and Arithmetic
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
C Programming Lecture-3 Keywords, Datatypes, Constants & Variables
Variables in C Topics Naming Variables Declaring Variables
Programming Fundamental-1
Variables in C Topics Naming Variables Declaring Variables
Presentation transcript:

CS1061 C Programming Lecture 4: Indentifiers and Integers A.O’Riordan, 2004

Identifiers C source code is made up of various characters typed at the keyboard: The 52 uppercase and lowercase alphabetic characters. The 10 decimal digits (0,1,…,9). Various punctuation and graphic characters (+,-, {, &, !, etc.). White space (space character, tabulation). The name that a variable or function can take is called its identifier. Identifiers can consist of letters, digits, and underscore characters, but must not begin with a digit. The limit on the size of an identifier is set by the particular C implementation you are using.

Choosing Identifiers Here are examples of valid identifiers: Speed count1 first_name _result BankAccNumber Person133 Here are some invalid identifiers: 4sure percent% Tips Be consistent with the naming scheme you adopt. Two popular conventions are to SquashNamesTogether or to use_many_underscores. Choose descriptive variable names – make code self-documenting.

Reserved Words C has a set of reserved words that you cannot use as identifiers. The following table gives a list of the reserved words: auto break case char class const continue default do double else entry enum extern float for goto if int long register return short signed sizeof static struct switch typedef union unsigned void volatile while

C Data Types C provides a comprehensive set of data types. A programmer can also define his/her own types. Type abstraction aids expressiveness, readability and correctness checking. Any number of variables can be created of a given type. The fundamental data types are: char, signed char, unsigned char, signed short int, signed int, signed long int, unsigned short int, unsigned int, unsigned long int, float, double, long double, bool Note: The keyword signed can be omitted and a type will default to the signed variant. Thus int is typically given instead of signed int.

Integral Types Numeric variables are an important part of any programming language. The type int is used for representing integers, and char for representing characters. Here is an example where we declare two variables count and answer, which are to have integer and character values respectively. int count; char answer; Variables must always be declared before they are used. These variables can be given initialisations in the declarations. Here are examples: int count = 0; char answer = ‘Y’;

Integral Types (continued) More than a single variable can be declared in a single line. For example: int current_size=0, max_size=100; These can be changed: current_size =50; max_size= current_size; Programming Tip It is always a good idea to initialise a variable in its declaration.

Binary Numbers Computers use binary (base 2) where each digit is either a 0 or 1. bit: binary digit byte: a group of 8 bits You are familiar with decimal (base 10): = 3     Binary works in a similar way: = = 1      2 + 0

Integer Constants Integer constants can be given in a C program in decimal, octal or hexadecimal notation. If an integer begins with letters 0x or 0X it is in hexadecimal If an integer begins with digit 0 it is in octal Otherwise it is in decimal An integer followed by either the letter l or L indicates it is long. An integer followed by either the letter u or u indicates it is unsigned. Examples: 20 0x (these are all ) l 1u

Integral Types (continued) A char is 1 byte (0-255) A short is usually 2 bytes but can be anything between char and int. An int is usually 4 bytes but is guaranteed at least 2 bytes ( to 32767) A long is usually 4 or 8 bytes but can be anything equal to or bigger than an int and guaranteed to be at least 4 bytes (-2,147,483,648 to 2,147,483,647) An unsigned int can store larger numbers than an int.

Size of an integer It is not dictated by the C standard what size an int will be. On some systems it will be two bytes whereas on other systems is could be four bytes. Therefore on a two byte machine, you can represent 2 16 states, the numbers –2 15, …,-1, 0, 1, …, You can determine the memory size allocated for a type by using the sizeof operator with single operand, which may be a type or a variable. int x; sizeof(int); sizeof x;