0% found this document useful (0 votes)
109 views

Hsslive-XI-CS-Chap5-Introduction To C Programming

This document provides an introduction to C++ programming, covering topics like character sets, tokens, keywords, identifiers, literals, punctuators, and operators. It defines these core elements and gives examples. It also includes sample questions from previous years' exam papers related to classifying and identifying tokens, literals, identifiers, and other elements in C++ code.

Uploaded by

Abhinand S
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
109 views

Hsslive-XI-CS-Chap5-Introduction To C Programming

This document provides an introduction to C++ programming, covering topics like character sets, tokens, keywords, identifiers, literals, punctuators, and operators. It defines these core elements and gives examples. It also includes sample questions from previous years' exam papers related to classifying and identifying tokens, literals, identifiers, and other elements in C++ code.

Uploaded by

Abhinand S
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Computer Science - XI

Chapter 5: Introduction to C++ Programming

Character set: The fundamental unit of C++ language. The character set of C++ is
categorized as (i) Letters (A – Z, a – z), (ii) Digits (0 – 9), (iii) Special characters (iv)White
spaces.

Tokens: The fundamental building blocks of the program. C++ has five types of tokens –
Keywords, Identifiers, Literals, Punctuators and Operators.

Keywords: The words (tokens) that convey a specific meaning to the language compiler.
These are also known as reserved words.

Identifiers: These are the user-defined words used to name different program elements
such as memory locations, statements, functions, objects, classes etc. The identifiers of
memory locations are called variables. The identifiers assigned to statements are called
labels. The identifiers used to refer a set of statements are called function names.

Rules for naming identifiers: An arbitrary long sequence of letters, digits and underscores.
The first character must be a letter or underscore ( _ ). White space and special characters
are not allowed. Keywords cannot be used. Upper and lower case letters are treated
differently.

Literals: Data items that never change their value during the program run. They are often
referred to as constants. Literals are of four types – Integer literals, Floating point literals,
Character literals and String literals.

Integer literals: The tokens constituted only by digits. They are whole numbers without
fractional part. Eg: 13. -76

Floating point literals: Also known as real constants. These are numbers having fractional
parts. These can be written in one of the two forms –fractional form or exponential form.
Eg: 4.35, 2.5e6, -5E-3 etc.

Character literal: A single character enclosed in single quotes. Eg: ‘a’, ‘9’, ‘+’ etc.

Escape sequences: These special character constants that represent non-graphic symbols. It
consists of a backslash (\) followed by one or more specific characters.

String constant: A sequence of one or more characters enclosed within a pair of double
quotes is called. Eg: “Hello friends”, “123” etc.

Punctuators: Some special symbols that have syntactic or semantic meaning to the
compiler.
Operator: A symbol that tells the compiler about a specific operation. They are the tokens
that trigger some kind of operation. The operator is applied on a set of data called
operands.
1
Joy John’s CS Capsule
Computer Science - XI
Questions from Previous Years’ Question Papers
1. Identify and classify tokens in the following C++ statement:
cout << “The Missile Man”; (2) (July 2017)
2. Identify the invalid literals from the following and write reason for each:
a) 2E3.5 b) “9” c) ‘hello’ d) 55450 (2) (March 2017)
3. Which of the following is a user-defined name?
a) Keyword b) Identifier c) Escape sequence d) All of these
(1) (Sept. 2016)
4. Identify whether the following are valid identifiers or not. If not, give reason.
a) Break b) Simple.interest (2) (Sept. 2016)
5. What is preprocessor directive statement? Explain with an example. (2) (Sept. 2016)
6. Some of the literals in C++ are given below. How do they differ?
(5, ‘5’, 5.0, “5”) (2) (March 2016)
7. A student wants to insert his name and school address in the C++ program that he has
written. But this should not affect the compilation or execution of the program. How is
it possible? Give an example. (2) (March 2016)
8. The following are some invalid identifiers. Specify its reason.
a) Sum of digits b) 1year c) First.jan d) for (2) (Sept.2015)
9. Mention the purpose of tokens in C++. Write names of any four tokens in C++.
(2) (March 2015)

2
Joy John’s CS Capsule

You might also like