Download presentation
Presentation is loading. Please wait.
2
Data types Data types Basic types
Byte, short, int, long, Char, Float, double, void Derived types array, pointers, references User defined datatype structure, union, class, type def.
3
Data Types: Display 1.2 Simple Types (1 of 2)
4
Data Types: Display 1.2 Simple Types (2 of 2)
5
C++ Tokens C++ Tokens are the smallest individual units of a program.
Following are the C++ tokens : (most of c++ tokens are basically similar to the C tokens) Keywords Identifiers Constants Variables Operators
6
Keywords (in C) Auto double int struct break else long switch case
enum register typedef char Extern return union const float short unsigned continue for signed void default goto sizeof volatile do if static while
7
Keywords (additionally in C++)
asm bool catch class const_cast delete dynamic_cast export false friend inline mutable namespace new operator private protected public reinterpret_cast static_cast template this throw true try typeid typename using virtual wchar_t
8
Identifiers Identifiers are used as the general terminology for naming of variables, functions and arrays. These are user defined names Rules: They must begin with a letter or underscore(_). They must consist of only letters, digits, or underscore. No other special character is allowed. It should not be a keyword. It must not contain white space. It should be up to 31 characters long as only first 31 characters are significant.
9
Identifiers NAME REMARK int _A9 Valid
double Temp.var Invalid as it contains special character other than the underscore void Invalid as it is a keyword char a_a Valid Int asm
10
Constants (literals) Syntax: const data_type variable_name; (or)
”
11
Types of Constants: Integer constants –
Example: 0, 1, 1218, const int x=1218; Real or Floating point constants – Example: 0.0, , const float x= ; Character constants – Example: ‘a’, ‘A’, ‘z’ char a=‘d’ , char q=‘Z’ String constants – Example: char s[]=“GeeksforGeeks”
12
Strings char string[20] = {‘g’, ’e’, ‘e’, ‘k’, ‘s’, ‘f’, ‘o’, ‘r’, ‘g’, ’e’, ‘e’, ‘k’, ‘s’, ‘\0’}; char string[20] = “geeksforgeeks”; char string [] = “geeksforgeeks ABCD”;
13
Special Symbols: Brackets[]: Parentheses(): Braces{}: comma (, ):
semi colon : asterick (*): It is used to create pointer variable. assignment operator: It is used to assign values. pre processor(#): The preprocessor is a macro processor that is used automatically by the compiler to transform your program before actual compilation.
14
Operators: Unary Operators (a++, --b) Binary Operators (a+b,
Ternary Operators (Substitute for if-else) (a>b ? A: B)
15
Types of operators Arithmetic Operators Relational Operators
Logical Operators Bitwise Operators Assignment Operators
16
Arithmetic
17
== != > < >= <= Relational
Operator Description Example == Checks if the values of two operands are equal or not, if yes then condition becomes true. (A == B) is not true. != Checks if the values of two operands are equal or not, if values are not equal then condition becomes true. (A != B) is true. > Checks if the value of left operand is greater than the value of right operand, if yes then condition becomes true. (A > B) is not true. < Checks if the value of left operand is less than the value of right operand, if yes then condition becomes true. (A < B) is true. >= Checks if the value of left operand is greater than or equal to the value of right operand, if yes then condition becomes true. (A >= B) is not true. <= Checks if the value of left operand is less than or equal to the value of right operand, if yes then condition becomes true. (A <= B) is true.
18
Logical Operator Description Example && Called Logical AND operator. If both the operands are non-zero, then condition becomes true. (A && B) is false. || Called Logical OR Operator. If any of the two operands is non-zero, then condition becomes true. (A || B) is true. ! Called Logical NOT Operator. Use to reverses the logical state of its operand. If a condition is true, then Logical NOT operator will make false. !(A && B) is true.
19
Bitwise & | ^ ~ << >>
Binary AND Operator copies a bit to the result if it exists in both operands. (A & B) will give 12 which is | Binary OR Operator copies a bit if it exists in either operand. (A | B) will give 61 which is ^ Binary XOR Operator copies the bit if it is set in one operand but not both. (A ^ B) will give 49 which is ~ Binary Ones Complement Operator is unary and has the effect of 'flipping' bits. (~A ) will give -61 which is in 2's complement form due to a signed binary number. << Binary Left Shift Operator. The left operands value is moved left by the number of bits specified by the right operand. A << 2 will give 240 which is >> Binary Right Shift Operator. The left operands value is moved right by the number of bits specified by the right operand. A >> 2 will give 15 which is
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.