0% found this document useful (0 votes)
5 views8 pages

Lesson3 - C - Tokens

The document provides an overview of C++ tokens, including variables, identifiers, keywords, constants, and data types, essential for programming in C++. It outlines objectives for students to understand input/output functions, familiarize with C++ terminology, and construct basic C++ structures. Additionally, it includes resources for further learning and sample codes to illustrate concepts.

Uploaded by

jervinbucu30
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views8 pages

Lesson3 - C - Tokens

The document provides an overview of C++ tokens, including variables, identifiers, keywords, constants, and data types, essential for programming in C++. It outlines objectives for students to understand input/output functions, familiarize with C++ terminology, and construct basic C++ structures. Additionally, it includes resources for further learning and sample codes to illustrate concepts.

Uploaded by

jervinbucu30
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

DON HONORIO VENTURA STATE

UNIVERSITY
Cabambangan, Villa de Bacolor 2001, Pampanga,

C++ Tokens
Descriptio
n
A token is the smallest element of a program that is meaningful to the
compiler. A variable provides named storage that programs can manipulate.
Each variable in C++ has a specific type, which determines the size and
layout of the variable's memory; the range of values that can be stored
within that memory; and the set of operations that can be applied to the
variable. C++ keywords, identifiers, constants and data types are used to
give meaning to C++ variables.

Objectives
After completing the module, the students are expected to:
 Understand the input/output functions of C++ programming language
 Familiarize with the terms used in C++ programming language
 Able to construct the basic structure of C++
 Able to write codes using C++ programming language in
Dev C++ IDE Instructions

 Engage students with the topic by demonstrating them how to construct


functions in Dev C++ IDE.
 Elaborate each function to have a deeper understanding in constructing
the basic C++ structure.
 Discuss content and answer questions. Check for understanding by asking:

 What is the difference between keywords, identifiers, constants and


data types in defining a variable?
 What is the difference between float and double data type?
 Why identifiers are important in defining a variable?
 What is the significance of keywords in C++ programming language?
DON HONORIO VENTURA STATE
UNIVERSITY
Cabambangan, Villa de Bacolor 2001, Pampanga,

Resources (Educational Materials):


url: videos: https://www.youtube.com/watch?
https://goalkicker.com/CPlusPlusBook/ v=vLnPwxZdW4Y
https://www.w3schools.com/cpp/cpp_getstarted.asp https://www.youtube.com/watch?v=_bYFu9mBnr4
http://www.cplusplus.com/info/description/ https://www.youtube.com/watch?v=JBjjnqG0BP8
https://www.programiz.com/cpp-programming
https://www.studytonight.com/cpp/introduction-to-
cpp.php
https://docs.oracle.com/cd/E19957-01/806-
3569/Standard.html
https://docs.microsoft.com/en-us/cpp/standard-
library/iostream?view=vs-2019
https://www.softwaretestinghelp.com/iomanip-
functions-in-cpp/

Variables

The usefulness of the "Hello World" programs is rather questionable. We had to write
several lines of code, compile them, and then execute the resulting program, just to
obtain the result of a simple sentence written on the screen. It certainly would have been
much faster to type the output sentence ourselves.

However, programming is not limited only to printing simple texts on the screen. In order
to go a little further on and to become able to write programs that perform useful tasks
that really save us work, we need to introduce the concept of variables.

Let's imagine that I ask you to remember the number 5, and then I ask you to also
memorize the number 2 at the same time. You have just stored two different values in
your memory (5 and 2). Now, if I ask you to add 1 to the first number I said, you should be
retaining the numbers 6 (that is 5+1) and 2 in your memory. Then we could, for example,
subtract these values and obtain 4 as result.

The whole process described above is a simile of what a computer can do with two
variables. The same process can be expressed in C++ with the following set of
statements:
DON HONORIO VENTURA STATE
UNIVERSITY
Cabambangan, Villa de Bacolor 2001, Pampanga,

Obviously, this is a very simple example, since we have only used two small integer
values, but consider that your computer can store millions of numbers like these at the
same time and conduct sophisticated mathematical operations with them.

Identifiers
A C++ identifier is a name used to identify a variable, function, class, module, or
any other user- defined item. An identifier starts with a letter A to Z or a to z or an
underscore (_) followed by zero or more letters, underscores, and digits (0 to 9).

C++ does not allow punctuation characters such as @, $, and % within identifiers. C++ is
a case-sensitive programming language. Thus, Manpower and manpower are two different
identifiers in C++.

Examples of acceptable identifiers:


DON HONORIO VENTURA STATE
UNIVERSITY
Cabambangan, Villa de Bacolor 2001, Pampanga,

Keywords
Keywords are the reserved words in C++ libraries used to perform an internal
operation.

Examples of C++ keywords:

Data Types
In C++, data types are declarations for variables. This determines the type and size
of data associated with variables.

Data Meaning Size (in Explanation


Type Byte)
int Integer 2 or 4 Used to indicate integers
float Floating-point 4 Used to store floating-point
numbers (decimals and
double Double floating- 8
exponential)
point
char Character 1 Used for characters and are
enclosed
inside single quotes
DON HONORIO VENTURA STATE
UNIVERSITY
Cabambangan, Villa de Bacolor 2001, Pampanga,

bool Boolean 1 Used in conditional statements


and
loops
string Text Depending on Used in storing text
how many
char

Sample Code:
DON HONORIO VENTURA STATE
UNIVERSITY
Cabambangan, Villa de Bacolor 2001, Pampanga,

Constants
Constants are expressions with a fixed value.

 Literals - are the most obvious kind of constants. They are used to express
particular values within the source code of a program. We have already used some
in previous chapters to give specific values to variables or to express messages we
wanted our programs to print out. Literal constants can be classified into: integer,
floating-point, characters, strings, Boolean, pointers and user-defined literals.
Example: a = 5;

 Integer Numerals – these are numerical constants that identify integer values.
They don’t
need to be enclosed in quotes or other special character.
Example:

 Decimal Numerals – C++ allows the use of octal numbers (base 8) and
hexadecimal numbers (base 16) as literal constants. For octal literals, the
digits are preceded with a 0 (zero) character and for hexadecimal they are
preceded by the characters 0x (zero, x)
Example:

These literal constants have a type, just like variables. By default, integer
literals are of type int. However, certain suffixes may be appended to an
integer literal to specify a different integer type:
DON HONORIO VENTURA STATE
UNIVERSITY
Cabambangan, Villa de Bacolor 2001, Pampanga,

Unsigned may be combined with any of the other two in any order to form
unsigned long or unsigned long long.
Example:

 Floating Point Numerals – Express real values, with decimals and/or


exponents. They can include either a decimal point, an e character that
expresses scientific notations.
Example:

The default type for floating-point literals is double. Floating-point literals of


type float or long double can be specified by adding one of the following suffixes: f
or F for float; l or L for long double.
Example:

 Character and String Literals – They are enclosed in quotes.

Example: -single-character literals

- String literals

Character and string literals can also represent special characters that are
difficult or impossible to express otherwise in the source code of a program, like
newline (\n) or tab (\t). These special characters are all of them preceded by a
backslash character (\). These are the following list of the single character escape
codes:
DON HONORIO VENTURA STATE
UNIVERSITY
Cabambangan, Villa de Bacolor 2001, Pampanga,

References:

 Goodrich, Michael et.al (2011). Data Structures and Algorithms in C++. John Wiley & Sons Inc,
United States of America
 Educational Technology Journals. http://www.educational-software-directory.net/publications/journals
 CPlusPlusNotesForProfessionals. http://www.GoalKicker.com
 C++ Tutorials. http://www.programiz.com
 C++ Tutorials. http://www.w3schools.in

You might also like