Constants, Variables and Datatypes
Constants, Variables and Datatypes
and Datatypes
Character Set
Characters in C are grouped into following categories :
4. White spaces :
Blank Space
Horizontal tab
Carriage return
New line
Form Feed
Trigraph Sequences
Trigraph Sequence Translation
??= # number sign
??( [ left bracket
??) ] right bracket
??< { left brace
??> } right brace
??! | vertical bar
??/ \ back slash
??’ ^ caret
??- ~ tilde
C Tokens
keywords : float, for, while
special Symbols : [ ] { } ( ) $
Keywords and Identifiers
Keyword :
meaning of word is known to compiler
Identifier :
name given by user to variable, function ….
Keywords
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
Identifiers
Identifiers refer to the names of variables, functions and arrays.
Permissible character for naming :
alphabet a-z, A-Z
underscore _
digit 0,1,2…..9
Primary Secondary
Numeric Character
Hexadecimal
Decimal Integer Octal Integer
Integer
digits 0,1,..9 digits o,1,….7 digits 0,1,….9
A..F/a…f
Ex., 123 037 0X2
-321 0435 0x
+78 0551 0x9F
0 0 0Xbcd
Integer Constants
16-bit m/c : -32768 to +32767
32-bit m/c : -2147483648 to +2147483647
Exponential(Scientific)
Decimal Notation
notation
Ex., 0.0083
mantissa e exponent
-0.75
435.36 Ex., 12e-2 -1.2E-1 3.1e3
+247.0
-.71 7500000000 7.5e9 / 75e8
.95 0.000000368 -3.68E-7
Example of Numeric Constant
698354L
25,000
+5.0E3
3.5e-5
7.1e 4
-4.5e-2
1.5E+2.5
$255
0X7B
Single Character Constants
Single character enclosed within a pair of single quote
marks.
Ex.,
‘X’ ‘;’ ‘’ ‘5’
printf(“%d”, ‘a’); 97
printf(“%c”, ‘97’); a
Ex.,
“Hello” “X” “?---…!” “5+3”
“6587” “Have a nice day”
Backslash Character Constant/
Escape Sequence
Constant Meaning
‘\a’ Audible
‘\b’ Back space
‘\f’ Form feed
‘\n’ New line
‘\r’ Carriage return
‘\t’ Horizontal tab
‘\v’ Vertical tab
‘\’’ Single quote
‘\”’ Double quote
‘\?’ Question mark
‘\\’ Backslash
‘\0’ Null
Datatypes
Datatypes
Primary/Fundamental /
Primitve Derived User-defined
Data types Data types Data types
Integer
Array Structure
Character
Pointer Union
Float
Function Enum
Double
Datatypes
Size and Range of Data Types on a 16-bit Machine
Type Size(Bits) Range
char / signed char 8 -128 to +127 %c
unsigned char 8 0 to 255 %c
int / signed int 16 -32,768 to 32,767 %d
unsigned int 16 0 to 65535 %u
short int / signed short int 8 -128 to 127 %d
unsigned short int 8 0 to 255 %u
long int / signed long int 32 -2,147,483,648 to 2,147,483,647 %ld
unsigned long int 32 0 to 4,294,967,295 %lu
float 32 3.4E-38 to 3.4E+38 %f
double 64 1.7E-308 to 1.7E+308 %lf
long double 80 3.4E-4932 to 1.1E+4932 %Lf
Operators & Expression
Operators
<
+ &
<= ,
- && |
> ++ sizeof
* || = ?: ^
>= -- * &
/ ! <<
== . ->
% >>
!=
Defining Member Functions :
Inside the Class Definition
Replace the function declaration by the actual function definition inside the class.
class item
{
int number;
float cost;
public :
void getdata(int a, float b);
void putdata(void)
{
cout << "Number :" << number << "\n";
cout << "Cost :" << cost << "\n";
}
};
Defining Member Functions :
Inside the Class Definition
When a function is defined inside a class, it is treated as an
inline function.
Therefore, all the restrictions and limitations that apply to an
inline function are also applicable here.