CBSE 2026 results are out, Mukul scored a perfect 100/100 in Computer ScienceSee all toppers →

KwickAcademy Cyber Safety and Ethics · 8 min · free

C++ Tokens, Data Types, Variables and Operators

8 min4 KwickClipsFull text belowFree
Next lesson →Kajal Ma'am (MCA), teaching since 2004Remembered in this browser

C++ tokens are keywords, identifiers, literals, operators and punctuators; data types like int and double decide what a variable holds. int divided by int drops the decimal, so 7 / 2 gives 3.

Follows the syllabus of: NIOS Senior Secondary Computer Science (330)

On screen in this lesson

Tokens: smallest pieces

TokenMeaningExample
KeywordReserved wordint, return
IdentifierName you choosemarks, total
LiteralFixed value45, 'A', 3.5
OperatorDoes an action+, *, ==
PunctuatorSeparates code; , { }

Rules for identifiers

Use letters, digits and underscore only
Cannot start with a digit: 2marks is wrong
Cannot be a keyword: int is wrong
Case sensitive: Marks and marks are different

Basic data types

TypeStoresUsual size
intWhole number4 bytes
floatDecimal, 6-7 digits4 bytes
doubleDecimal, 15 digits8 bytes
charOne character1 byte
booltrue or false1 byte

Operators

GroupOperatorsExample
Arithmetic+ - * / %7 % 2 is 1
Relational< > <= >= == !=5 > 3 is 1
LogicalAND, OR, NOTa && b
Assignment= += -=x += 5
Increment++ --count++

Operator precedence

OrderOperatorsNote
1 (first)( )Brackets
2++ -- !Unary
3* / %Left to right
4+ -Left to right
5< > == !=Compare
6 (last)&& then ORLogical

Conversion rules to remember

Smaller type is promoted to larger: int to double
char in maths uses its ASCII code: 'A' + 1 is 66
double to int drops the decimal: 9.8 becomes 9
Cast before dividing, not after

Quick answers

Why does 7 / 2 print 3?

Both are int, so the decimal part is dropped.

How do you get 112.5 from 450 / 4?

Cast first: (double) total / 4.

KwickClips from this lesson

Short clips, one idea each. Good for revision the night before.

The full lesson, in text

Hello students, welcome to Kwickprep. In C plus plus, seven divided by two prints three, not three point five. Why? By the end of this lesson you will know. We will learn tokens, data types, variables, constants, operators and type conversion.

A token is the smallest meaningful piece of a program, like a word in a sentence. Keywords are reserved words with a fixed meaning, like int and return. Identifiers are names you choose for variables and functions, like marks. Literals, also called constants, are fixed values like forty five or the letter A. Operators do an action, like adding or comparing. Punctuators, also called separators, include the semicolon, the comma and curly braces.

Exams often ask which names are valid, so learn four rules. An identifier may use letters, digits and the underscore only, so no spaces. It cannot start with a digit, so two marks written together is wrong. It cannot be a keyword like int. And C plus plus is case sensitive, so marks with a capital M is a different name.

A data type tells the computer what kind of value a variable holds and how much memory it needs. An int stores a whole number and usually takes four bytes. A float stores a decimal number with about six or seven digits of accuracy, in four bytes. A double stores a decimal with about fifteen digits, in eight bytes. A char stores one character in one byte. A bool stores true or false. Sizes can differ between compilers, so we say usual size.

The size of operator tells how many bytes a type uses. On a modern computer, int takes four bytes, double takes eight, and char takes one. So the output is four, eight, one.

A variable is a named box in memory whose value can change. Before using it, you declare it with a data type. Int runs equals forty eight creates the box and gives it a starting value, which is called initialising. A batter then hits a six, so runs becomes runs plus six. The program prints fifty four.

A constant is a value that cannot change after it is set. Add the keyword const before the type. Here pi is fixed at three point one four, and the radius is two. The area, pi times radius times radius, prints twelve point five six. If you try to change pi later, the compiler gives an error about assigning a read only variable. Older code also uses hash define to make constants.

An operator does an action on values, which are called operands. Arithmetic operators do maths, and the percent sign, modulus, gives the remainder. Relational operators compare, and a true answer prints as one. Logical operators join conditions. The double ampersand means and, double bar means or, and exclamation means not. One equals sign assigns, while double equals compares. The increment operator adds one, and the decrement operator subtracts one.

Here is the answer to our opening question. When both numbers are int, division throws away the decimal part, so seven by two gives three. The modulus gives the remainder, which is one. If even one number is a decimal, like seven point zero, the answer is three point five.

Plus plus written after a variable is post increment. It uses the old value first, then adds one. So the variable old gets five, and then a becomes six. The output is six, five. Pause and predict. What prints if we write plus plus a instead? Pre increment adds first, so both become six.

Precedence decides which operator works first, just like the bodmas rule in maths. Brackets always come first. Next come unary operators, which work on one value, like increment and not. Then multiply, divide and modulus, from left to right. Then add and subtract, also left to right. Then the comparing operators. Last come logical and, followed by logical or. Assignment happens at the very end.

Board exams love this kind of question. Two plus three times four is fourteen, because multiplication happens first. With brackets, two plus three is done first, giving twenty. In the last line, divide and multiply share the same level, so we go left to right. Six by three is two, times two is four, and twenty minus four is sixteen.

Type conversion means changing a value from one data type to another. Implicit conversion is done automatically by the compiler. Here, total by four is int divided by int, so the answer is one hundred twelve, and the point five is lost. Only then is it converted to double. So avg prints one hundred twelve, not one hundred twelve point five.

Explicit conversion, also called type casting, is done by you. Write the new type in brackets before the value. Now total becomes a double before dividing, so the answer is one hundred twelve point five. Modern C plus plus also offers static cast, which does the same job and is easier to spot.

Remember four rules about conversion. In a mixed expression, the smaller type is promoted to the larger type, like int to double. A char used in maths becomes its character code, so capital A plus one is sixty six. Storing a double in an int drops the decimal part, so nine point eight becomes nine, with no rounding. And always cast before you divide, not after.

Let us revise what we learned today. There are five kinds of tokens: keywords, identifiers, literals, operators and punctuators. Int, float, double, char and bool each store a different kind of value. A variable can change, but a const value cannot. Multiply, divide and modulus run before add and subtract, and brackets run first of all. Implicit conversion happens automatically, while a cast is written by you. Try the precedence program with your own numbers and predict before you run.

Courses that teach this

CourseUnit
NIOS Senior Secondary Computer Science (330)Module 3: Programming in C++
Programming All levels C++C++ Foundations

Voice-over in this lesson is AI-generated. The script is written and checked by Kajal Ma'am. Boards can revise a syllabus mid-year, so confirm anything you plan around against the official board circular. Keep your passwords, OTPs and ID numbers to yourself — we never ask for them. To reach Kajal Ma'am, use the WhatsApp button; sharing your number there is how we call you back.

Free to watch, no sign-up. Live classes with Kajal Ma'am are the paid course; these lessons stay free either way.

Want a plan that actually fits your board dates?

Ask Kajal Ma'am directly, 20+ years teaching computer science. Free demo class first, no payment.

Talk to Kajal Ma'am on WhatsApp

Or see the Class 12 Computer Science course →

Studying outside India?

We coach CBSE, IGCSE & international students across the globe, one-to-one, in your local time zone.

Visit International →