You are on page 1of 9

MUHAMMAD SAMI (BSCS)

November,2019.

PROGRAMMING FUNDAMENTALS

Keywords in C++
Keyword is a predefined or reserved word in C++ library with a fixed meaning and used to perform an
internal operation. C++ Language supports more than 64 keywords.

Every Keyword exists in lower case latter like auto, break, case, const, continue, int etc.

Keywords with definitions:-


char
 Used to declare character variables. This variable type is normally
8 bits (1 byte) long.

char c = ‘h’;

const (C++ only)


 Used to tell the compiler that a certain object should not be
modified once it has been initialized.

const int i = 5;
 Used to declare a pointer so that the value of the pointer (the
memory location to which it points) can be modified, but the data
in the memory location cannot be changed.

const int* j = new int(3);


 Used to declare a pointer so the that value of the pointer (the
memory location to which it points) cannot be modified, but the
data in that memory location can be changed.

int* const j = new int(3);


 Used to declare a member function that does not modify the
object’s state, meaning that it should be used for methods like
print so that data in the object cannot be changed accidentally. If
and attempt is made to modify the object in any way, a
compilation error will be triggered.

void print(bool verbose) const;

continue
 Used to jump to the next iteration of a loop. The following
example will print out all of the numbers from 1 to 20 except for
10.

 for(int i = 0; i < 21; i++)


 {
 if(i == 10)
 continue;
 cout << i << endl;
 }

default
 Used as a label to declare the default case of a switch statement.

 case 1: command1;
 command2;
 break;

 default: command1;
 command2;
 break;

delete (C++ only)


 Used to free memory allocated for a pointer back to the heap. The
argument should have been allocated through a call to new. To
delete an array, use the following form of delete: delete[]

 delete p;
delete[] pArray;

do
 Used to create a loop that is executed at least once. The
terminating condition is tested at the end of the loop.

 do
 {
 cout << "hello worldn";
 i++;
 } while(i < 5)

double
 Used to declare a double-precision floating-point type variable.
This variable type is normally 64 bits (8 bytes) long.

double d = 12.55;

else
 Used for an alternative condition in an if statement.

 if(i == 1)
 {
 // do something
 }
 else
 {
 // do something else
 }

float
 Used to declare a single-precision floating-point type variable.
This variable
type is normally 32 bits (4 bytes) long.

float f = 3.5;

for
 Used to create a loop that is meant to initialize, test and update a
variable.

 for(int i = 0; i < 10; i++)


 {
 cout << "i is " << i << endl;
 }

if
 Used to create a conditional branch statement so that different
code can be executed under different conditions. The conditions
are evaluated in the order that they appear in the code.

 if (i < 0)
 {
 cout << "i is negative";
 }
 else if(i == 0)
 {
 cout << "i is 0n";
 }
 else
 {
 cout << "i is posativen";
 }

int
 Used to declare an integer type variable. This variable type is
normally 32 bits (4 bytes) long.

int i = 3;

return
 Used to cause the execution to jump from the current function
back to the one that called it. An optional value can be returned
but the function must specify the type that it will return.

 return;
return 5;

short
 Used as a data type modifier for the int type to indicate that there
may be less bytes then the type has available. This variable type is
normally 16or 32bits (2 or 4bytes) long.

short int i = 5;

signed
 Used to specify that the number type provided could potentially
be negative, so it must be stored in a different format. This is the
default representation that is chosen by most compilers if either
signed or unsigned is not specified.

signed int i = -12;

unsigned
 Used to specify that the int or char provided can only be posative
and can therefore contain a larger number since there is no need
to worry about representation of negative numbers.

signed int i = -12;

Data Types:-
In computer programming, information is stored in a
computer memory with different data types. eg . char,int,float etc.
Range of data types:-
Integer Types:-
The following table provides the details of standard integer types with their
storage sizes and value ranges −

Type Storage size Value range

char 1 byte -128 to 127 or 0 to 255

unsigned char 1 byte 0 to 255

signed char 1 byte -128 to 127

-32,768 to 32,767 or -2,147,483,648 to


int 2 or 4 bytes
2,147,483,647

unsigned int 2 or 4 bytes 0 to 65,535 or 0 to 4,294,967,295

short 2 bytes -32,768 to 32,767


unsigned short 2 bytes 0 to 65,535

long 8 bytes -9223372036854775808 to 9223372036854775807

unsigned long 8 bytes 0 to 18446744073709551615

Floating-Point Types:-
The following table provide the details of standard floating-point types
with storage sizes and value ranges and their precision −

Type Storage size Value range Precision

float 4 byte 1.2E-38 to 3.4E+38 6 decimal places

double 8 byte 2.3E-308 to 1.7E+308 15 decimal places

long double 10 byte 3.4E-4932 to 1.1E+4932 19 decimal places

You might also like