Advertise

Friday, 20 September 2013

Short and Quick C++ [C plus plus] Programming Reference Sheet - World of Hacker

Please note, this is reference sheet and not tutorial, So, if you are already aware of C++ and is looking to refer back your C++, than this thread can come handy for you.





Including Headers


PHP Code:
#include  

#include is Directory location of "include" folder where all header files are saved and "<" & ">" are used to read the content inside the header file used.

Data Type


1. int => Integer Data Type Google Search Results for: int Data type in C Plus Plus
2. char => Character Data Type Google Search Results for: Character Data Type
3. float => Floating point Data Type Google Search Results for: float point Data Type 
4. double => double data type Google Search Results for: double data type in c plus plus 
5. void => void Google Search Results for: void type in c plus plus
6. bool => boolean data type Google Search Results for: boolean data type 

How to Add Comments in C++


Single Line Comment 

Code:
// This is Single line comment which starts with double forward slash

Multiple Line Comment

Code:
/*
This is
Multiple
Line
Comment
*/

Types of Operators

1. Arithemetic Operators

+ is used for Addition.
is used for subtraction.
* is used for multiplication.
/ is used for division.

2. Relational Operators

< is used for Less than.
> is used for Greater than.
<= is used for less than equal to.
>= is used for Greater than equal to.
== is used for Equal to.
!= is used for not Equal to.

3. Logical Operators

|| is used for LOGICAL OR.
&& is used for LOGICAL AND.
is used for LOGICAL NOT.

Pointers

Defining Pointer
Code:
int *ptr

Setting Address of Variable "var" to Pointer "ptr"
Code:
ptr = &var;

Using Pointer to set variable "var2" from Variable "var1"
Code:
int *ptr;
ptr = &var1;
var2 = *ptr;

IF Statement in Cplusplus [C++]


Code:
if ( )
{
        //Executing Your statement here.
}

IF Else in Cplusplus [C++]


Code:
if ( )
{
        //Executing Your statement here.
}
else
{
        // Executing your Statement here.
}

IF ElseIf else in Cplusplus [C++]


Code:
if ( )
{
        //Executing Your statement here.
}
else if ( )
{
        // Executing your Statement here.
}
else
{
        // Executing your Statement here.
}

For Loop in Cplusplus [C++]


Code:
for ( ; ; )
{
        //Executing Your statement here.
}

While loop in Cplusplus [C++]


Code:
while ( )
{
        //Executing Your statement here.
}

Do.. While loop in Cplusplus [C++]


Code:
do
{
        //Executing Your statement here.
} while ( );

Switch Case in Cplusplus [C++]


Code:
switch
{
        case :
                                         // Execute your statement here;
                                         break;
        case :
                                        // Execute your statement here;
                                        break;
        default:
                   // Execute Statement here.
                   break;
}

Arrays in Cplusplus [C++]


Array of name "hacker" of size 10 element, & integer rank of size 3 element
Code:
char hacker[10];
int rank[3];

To Know: Array Value Starts with 0.
Therefore, to access 1st element of an Array, Syntax will be :-

Code:
hacker[0] = 'K';
rank[0] = '1';

Input Output Operators in C plus plus [C++]

Input Operators in C plus plus is >>

Code:
cin >> variable_1;
cin >> variable_1, variable_2, variable_3;
[code]

Output Operators in C plus plus is [color=#FFD700]<<[/color]

[code]
cout << "Hello World of Hacker"

File Input / Output in Cplusplus [C++]


For this , you must include header file.
Code:
fstream file;
file.open("worldofhacker.txt", "mode") // for mode details see 3 code below
// To Read and Write, It will use same cin "[color=#FFD700]>>[/color]" and cout "[color=#FFD700]<<[/color]" style.
file >> variable_1; // This is for Input.
file << variable_2; // This is for Output.

To Read Entire Line :-
continued code.. from above
Code:
getline(file, line);

Reading and Writing Binary Data.
continued code... from above

Code:
file.read(memory_block, size);
file.write(memory_block, size);

Closing File in C plus plus [c++]
continued from above..

Code:
file.close();

File Mode Constants
Code:
ios::in  // Open File for Reading.
ios::out // Open File for writting.
ios::ate // Go to EOF [End of File], but operations can occur at any place.
ios::app // Takes output to End of File [EOF]
ios::trunc // Destroy the previous Content.
ios::nocreate // If file doesnot exist , open() function will fail.
ios::noreplace // if file already exist, open() will fail.

Prototype of Function in C plus plus [c++]

Code:
function_name
{
// function statement to execute;
}

Prototype of Class in C Plus Plus [c++]


Code:
class
{
    public:
         // add prototype for public methods;
    private:
        // add prototype for private methods;
   protected:
      // add prototype for protected methods;
};

Accessing Class value in C plus plus [c++]

To access variable "var" from method "worldofhacker" of class "Hackers"
We need to first create an object
Code:
Hackers KroKite;
krokite.worldofhacker(var);

Prototype for Structures in C plus plus [c++]

Code:
struct
{
data_type variable_name;
} ;

Accessing Data Structures in C plus plus [c++]

To access variable "var" from structure "worldofhacker
Code:
worlodfhacker.var = "Hello";

Well, Will Add Operator Overload, Friend Function Soon, For Now, I am going to take sleep, feeling sleepy
 
World of Hacker © 2011 Creative Commons License
World of Hacker by KroKite is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Based on a work at http://www.worldofhacker.com.
Permissions beyond the scope of this license may be available at https://groups.google.com/forum/#!newtopic/hackerforum.