DECLARATIONS. Character Set, Keywords, Identifiers, Constants, Variables. Designed by Parul Khurana, LIECA.

Similar documents
Programming in C++ 4. The lexical basis of C++

Basic Elements of C. Staff Incharge: S.Sasirekha

VARIABLES AND CONSTANTS

Data Types and Variables in C language

C Language, Token, Keywords, Constant, variable

Variables Data types Variable I/O. C introduction. Variables. Variables 1 / 14

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language

Fundamental Data Types. CSE 130: Introduction to Programming in C Stony Brook University

Gabriel Hugh Elkaim Spring CMPE 013/L: C Programming. CMPE 013/L: C Programming

ME240 Computation for Mechanical Engineering. Lecture 4. C++ Data Types

C Fundamentals & Formatted Input/Output. adopted from KNK C Programming : A Modern Approach

Programming and Data Structures

INTRODUCTION 1 AND REVIEW

ANSI C Programming Simple Programs

Java Basic Datatypees

DEPARTMENT OF MATHS, MJ COLLEGE

Binghamton University. CS-211 Fall Syntax. What the Compiler needs to understand your program

.. Cal Poly CPE 101: Fundamentals of Computer Science I Alexander Dekhtyar..

Presented By : Gaurav Juneja

C: How to Program. Week /Mar/05

6.096 Introduction to C++ January (IAP) 2009

Fundamental of Programming (C)

Chapter 2 - Introduction to C Programming

Tokens, Expressions and Control Structures

Variables in C. Variables in C. What Are Variables in C? CMSC 104, Fall 2012 John Y. Park

LESSON 1. A C program is constructed as a sequence of characters. Among the characters that can be used in a program are:

University of Technology. Laser & Optoelectronics Engineering Department. C++ Lab.

BSM540 Basics of C Language

Syntax and Variables

Character Set. The character set of C represents alphabet, digit or any symbol used to represent information. Digits 0, 1, 2, 3, 9

Standard 11. Lesson 9. Introduction to C++( Up to Operators) 2. List any two benefits of learning C++?(Any two points)

Basic Types, Variables, Literals, Constants

C OVERVIEW BASIC C PROGRAM STRUCTURE. C Overview. Basic C Program Structure

C How to Program, 6/e by Pearson Education, Inc. All Rights Reserved.

C OVERVIEW. C Overview. Goals speed portability allow access to features of the architecture speed

Work relative to other classes

LEXICAL 2 CONVENTIONS

Programming Fundamentals (CS 302 ) Dr. Ihsan Ullah. Lecturer Department of Computer Science & IT University of Balochistan

Introduction to C Programming. Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan

>B<82. 2Soft ware. C Language manual. Copyright COSMIC Software 1999, 2001 All rights reserved.

Overview of Computer Software and Programming Language

2/29/2016. Definition: Computer Program. A simple model of the computer. Example: Computer Program. Data types, variables, constants

Chapter 1 Problem Solving using Computer

Variables and Literals

UEE1302 (1102) F10: Introduction to Computers and Programming

PYTHON- AN INNOVATION

Introduction to C# Applications

HP C/iX Reference Manual

PROGRAMMAZIONE I A.A. 2018/2019

Fundamentals of Programming

Lecture 02 C FUNDAMENTALS

A Fast Review of C Essentials Part I

Chapter 2 THE STRUCTURE OF C LANGUAGE

CHAPTER-6 GETTING STARTED WITH C++

STUDY NOTES UNIT 1 - INTRODUCTION TO OBJECT ORIENTED PROGRAMMING

Variables in C. CMSC 104, Spring 2014 Christopher S. Marron. (thanks to John Park for slides) Tuesday, February 18, 14

In this session we will cover the following sub-topics: 1.Identifiers 2.Variables 3.Keywords 4.Statements 5.Comments 6.Whitespaces 7.Syntax 8.

Full file at C How to Program, 6/e Multiple Choice Test Bank

1.1 Introduction to C Language. Department of CSE

Differentiate Between Keywords and Identifiers

Computers Programming Course 5. Iulian Năstac

Basic Types and Formatted I/O

Unit 4. Input/Output Functions

CSC 1107: Structured Programming

Data types, variables, constants

ITC213: STRUCTURED PROGRAMMING. Bhaskar Shrestha National College of Computer Studies Tribhuvan University

C - Basic Introduction

Programming in C and Data Structures [15PCD13/23] 1. PROGRAMMING IN C AND DATA STRUCTURES [As per Choice Based Credit System (CBCS) scheme]

ADARSH VIDYA KENDRA NAGERCOIL COMPUTER SCIENCE. Grade: IX C++ PROGRAMMING. Department of Computer Science 1

The C++ Language. Arizona State University 1

Procedures, Parameters, Values and Variables. Steven R. Bagley

XC Specification. 1 Lexical Conventions. 1.1 Tokens. The specification given in this document describes version 1.0 of XC.

Java Notes. 10th ICSE. Saravanan Ganesh

LECTURE 02 INTRODUCTION TO C++

The component base of C language. Nguyễn Dũng Faculty of IT Hue College of Science

Manual. Subject Code: CS593. Computer Science and Engineering

Lexical Considerations

Number Systems, Scalar Types, and Input and Output

EDIABAS BEST/2 LANGUAGE DESCRIPTION. VERSION 6b. Electronic Diagnostic Basic System EDIABAS - BEST/2 LANGUAGE DESCRIPTION

Lexical Considerations

CMSC 104 -Lecture 5 John Y. Park, adapted by C Grasso

ME 172. Lecture 2. Data Types and Modifier 3/7/2011. variables scanf() printf() Basic data types are. Modifiers. char int float double

ET156 Introduction to C Programming

Fundamentals of Programming. Lecture 11: C Characters and Strings

Programming. C++ Basics

Programming for Engineers Introduction to C

1 Lexical Considerations

BITG 1233: Introduction to C++

1. What type of error produces incorrect results but does not prevent the program from running? a. syntax b. logic c. grammatical d.

Chapter 2. Lexical Elements & Operators

C++ Basics. Lecture 2 COP 3014 Spring January 8, 2018

Introduction to the C Programming Language

3 The Building Blocks: Data Types, Literals, and Variables

Unit-II Programming and Problem Solving (BE1/4 CSE-2)

C++ character set Letters:- A-Z, a-z Digits:- 0 to 9 Special Symbols:- space + - / ( ) [ ] =! = < >, $ # ; :? & White Spaces:- Blank Space, Horizontal

Laboratory 2: Programming Basics and Variables. Lecture notes: 1. A quick review of hello_comment.c 2. Some useful information

2.1. Chapter 2: Parts of a C++ Program. Parts of a C++ Program. Introduction to C++ Parts of a C++ Program

Computer Science & Information Technology (CS) Rank under AIR 100. Examination Oriented Theory, Practice Set Key concepts, Analysis & Summary

CS149: Elements of Computer Science. Fundamental C++ objects

Transcription:

DECLARATIONS Character Set, Keywords, Identifiers, Constants, Variables

Character Set C uses the uppercase letters A to Z. C uses the lowercase letters a to z. C uses digits 0 to 9. C uses certain Special Characters.

Character Set The special characters are listed below:- + - * / = % & #!? ^ ~ \ < > ( ) [ ] { } : ;., _ WHITE SPACE Most versions of the language also allow certain other characters, such as @ and $, to be included within strings and comments. White space includes new lines, tabs, space..

Identifiers Identifiers are the names that are given to various program elements, such as variables, functions and arrays. Identifiers consist of letters and digits, in any order, except that the first character must be a letter. Both UPPER and lowercase letters are permitted.

Identifiers Note: Upper case and lowercase letters are not interchangeable ( i.e., an uppercase letter is not equivalent to the corresponding lowercase letter.) The underscore ( _ ) character can also be included, and is considered to be a letter. An underscore is often used in the middle of an identifier. An identifier may also begin with an underscore.

Valid Invalid Identifiers The following names are valid Identifiers: x y12 sum_1 _tempera names area tax_rate GOTO The following names are Invalid Identifiers: 1th The first character must be a letter. x Illegal Character ( ). rder-no Illegal Character ( - ). rror flag Illegal Character (blank space). goto Reserved word (keyword).

Important - Identifiers Note: As identifier can be arbitrarily long. Some implementations of C recognize only the first eight characters, though most implementations recognize more ( typically 31 characters).

Example - Identifiers The identifier file_manager and file_management are both grammatically valid. Some compilers may be unable to distinguish between them, however, because the first eight characters are same for each identifier. Therefore, only one of these identifiers should be used in a single C program.

Keywords There are certain reserved words, called keywords, that have standard, predefined meanings in C. These keywords can be used only for their intended purpose, they cannot be used as programmer defined identifiers.

Standard Keywords The standard keywords are:- auto extern sizeof break float static case for struct char goto switch const if typedef continue int union default long unsigned do register void double return volatile else short while enum signed

Standard Keywords Some compilers may also include some or all of the following keywords: ada far near fortran asm pascal Entry huge Note that the keywords are all lowercase. Since uppercase and lowercase characters are not equivalent, it is possible to utilize an uppercase keyword as an identifier.

Constants There are four basic types of constants in C. They are: Integer constants. Floating-point constants. Character constants. String constants. Symbolic constants. Non symbolic constants are also known as literals.

Constants Moreover, there are several different kinds of integer and floating-point constants, as discussed below: Integer and Floating-point constants represent numbers. They are often referred to collectively as numeric type constants.

Rules for Numeric Type Constants Commas and blank spaces cannot be included within the constant. The constant can be preceded by minus (-) sign, if desired. The value of a constant cannot exceed specified minimum and maximum bounds. For each type of constant these bounds will vary from one C compiler to another.

Integer Constants An integer constant is an integer-valued constant. Thus, it consists of a sequence of digits. Integer constants can be written in three different number systems: decimal(base 10), octal(base 8) and hexadecimal(base 16).

Decimal Integer Constant A decimal integer constant can consist of any combination of digits taken from the set 0 through 9. if the constant contains two or more digits, the first digit must be something other than 0.

Valid Invalid Integer Constants Several valid decimal integer constants are shown below: 0 1 743 5280 32767 9999 The following decimal integer constants are written incorrectly for the reasons stated. 12,245 Illegal Character (, ). 36.0 Illegal Character (. ). 10 20 30 Illegal Character ( blank space ). 123-45-6789 Illegal Character ( - ). 0900 the first digit cannot be zero

Octal Integer Constant An octal integer constant can consist of any combination of digits taken from the set 0 through 7. However the first digit must be 0, in order to identify the constant as an octal number.

Valid Invalid Integer Constants Several valid octal integer constants are shown below: 0 01 0743 077777 The following octal integer constants are written incorrectly for the reasons stated. 743 Does not begin with 0. 05280 Illegal digit ( 8 ). 0777.777 Illegal character (. ).

Hexadecimal Integer Constant A hexadecimal integer constant must begin with either 0x or 0X. It can then be followed by any combination of digits taken from 0 to 9 and a through f ( either upper or lowercase). Note that the letters a through f ( or A through F) represent the (decimal) quantities 10 through 15, respectively.

Valid Invalid Integer Constants Several valid hexadecimal integer constants are shown below: 0x 0X1 0X7FFF 0xabcd The following hexadecimal integer constants are written incorrectly for the reasons stated. 0X 12.34 Illegal character (. ). 0BE38 Does not begin with 0x or 0X. 0x.4bff Illegal character (. ). 0XDEFG Illegal character ( G ).

Floating-Point Constants A floating-point constant is a base-10 number either a decimal point or an exponent (or both). The interpretation of a floating-point constant with an exponent is essentially the same as scientific notation, except that the base 10 is replaced by the letter E or e. Thus, the number 1.2 10-3 would be written as 1.2E-3 or 1.2e-3. This is equivalent to 0.12e-2,or 12e- 4, etc.

Valid Invalid Floating-point Constants Several valid floating-point constants are shown below: 0. 1. 0.2 827.602 50000. 0.000743 12.3 315.0066 2E-8 0.006e-3 1.6667E+8.12121212e12 The following are not valid floating-point constants for the reasons stated. 1 Either a decimal point or an exponent must be present. 1,000.0 Illegal character (, ). 2E+10.2 3E 10 The exponent must be an Integer quantity. Illegal character ( blank space) in the exponent.

Character Constants A character constant is a single character, enclosed in apostrophes (i.e., single quotation marks). Character constants have integer values that are determined by the computer s particular character set. Most computers, and virtually all personal computers, make use of ASCII (i.e., American Standard Code for Information Interchange) character set.

Valid Character Constants Several valid character constants are shown below: A x 3 Blank space Several character constants and their corresponding values, as defined by the ASCII character set, are shown below: Constant Value A 65 x 120 3 51 Constant Value? 63 32

String Constants A string constant consists of any number of consecutive characters ( including none), enclosed in (double) quotation marks.

Valid String Constants Several valid string constants are shown below: green Washington, D.C. 20005 270-32-3456 $19.95 THE CORRECT ANSWER IS: 2*(I+3)/J Line 1\n Line 2\n Line 3 Note that the string constant Line 1 \n Line 2\n Line 3 extends over three lines because of newline characters that are embedded within the string.

Symbolic Constants A symbolic constant is a name that substitutes for a sequence of characters. The characters may represent a numeric constant, a character constant or a string constant. Thus a symbolic constant allows a name to appear in place of a numeric constant, a character constant or a string. When a program is compiled, each occurrence of a symbolic constant is replaced by its corresponding character sequence.

Symbolic Constants Symbolic constants are usually defined at the beginning of a program. A symbolic constant is defined by writing # define name text Or const data-type name = value; where name represents a symbolic name, typically written in uppercase letters, and text represents the sequence of characters that is associated with the symbolic name.

Variables A variable is an identifier that is used to represent some specified type of information within a designated portion of the program. In its simplest form, a variable is an identifier that is used to represent a single data item i.e., a numerical quantity or character constant.

Variables A given variable can be assigned different data items at various places within the program. Thus, the information represented by the variable can change during the execution of the program. However, the data type associated with the variable cannot change.

Escape Sequences Certain non printing characters, as well as the backlash ( \ ) and the apostrophe ( ), can be expressed in the terms of escape sequences or backslash character constants.

Escape Sequences An escape sequence always begin with a backward slash and is followed by one or more special characters. For example, a line feed (LF), which is referred to as a newline in C can be represented as \n. Such escape sequences always represent single characters, even though they are written in terms of two or more characters.

Escape Sequences The following are the commonly used escape sequences: Character Escape Sequence ASCII Value bell (alert) \a 007 backspace \b 008 horizontal tab \t 009 vertical tab \v 011 newline ( line feed ) \n 010 form feed \f 012 carriage return \r 013 quotation mark ( ) \ 034 apostrophe \ 039 question mark (? \? 063 backslash \\ 092 null Designed by Parul Khurana, \0LIECA. 000

Practice Questions List 10 valid and 10 invalid identifiers other than those mentioned in your textbook and this presentation. Separate the valid decimal, octal and hexadecimal literals from the following:- 00.5, 0.0.5, 0.8E+0.8, 786, 13B, 0xLPU, 0x87e3fa Give the alternative declaration of following symbolic constants: # define CSE101 C const int CSE = 101 const char city = J ; int const city = N ;

Practice Questions Comment on the following code: #define int 100 and how does this declaration behave for the following:- int x; int; printf( %d, x);