C++ FUNDAMENTALS (IDENTIFIER, VARIABLE )

MelissaGuillermo1 7 views 30 slides Aug 29, 2024
Slide 1
Slide 1 of 30
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30

About This Presentation

FUNDAMENTALS C++


Slide Content

C++ Data Types

Bjarne Stroustrup

Data types A  data type  is a classification that dictates what a variable or object can hold

3 Basic Major Data Types Numerical Alphabetic Logical

Numerical Two broad categories Integer numbers Whole number 3 types : int , short and long) Floating point numbers 2 types: float and double Can be represented by Decimal: 3.1478 Scientific notation: 2.75e3 same as 2.75 x 10 3

Alphabetic Data Type Character Data type Store a single character Represented in single quote: ‘x’ , ‘A’ Strings Data type Store 2 more characters : “Melissa” or “apple” Keyword is string

Logical Data Supports two vaues : true or false Keyword: bool

C++ Primitive Data Types Primitive types integral floating char short int long bool float double long double unsigned

What is an Identifier? An identifier is the name to denote labels, types, variables, constants or functions, in a C++ program. C++ is a case-sensitive language. Age is not age Identifiers should be descriptive Using meaningful identifiers is a good programming practice

Rules in Naming Identifier You can use upper and lowercase letters, digits from 0 to 9, and underscore(_). The first character must be letter or underscore ( _ ). Don’t contains any blank,<,>,&,!,%,^,*,…etc. C++ is case sensitive –uppercase and lowercase letters are different, so a1 and A1 are different identifier. Not a keyword( int , float, double char, void, return main) Don’t give the same name to two different variables .

The C++ Key Words

Variable Location on computer’s memory to store data then use and change its value in a program

[data type] [variable name] = initial value; Variable declaration

Variable Declaration

Constant Fixed values keyword: const Declaration: const [data type] [name] = initial value example const float pi = 3.14159;

Arithmetic Operators

Special Characters

Common Escape Sequences

Sample Program Write a program in C++ to print the sum of two numbers Sample output

Write a program in C++ to add two numbers accept throughkeyboard .

Using getline
Tags