Saturday, November 8, 2014

C++ Beginners - Few Tips

Hi, Everyone

Hope you all are good.
From last year I was trying to return back and finally I'm back. :)
Lot's of people have requested me to return back and appreciated my blog.
I'm glad that so many people liked my blog so much. Thanks to all who spend there precisions time to read it.
Thanks Again!! :)

Today, in this post I want to point out few basic things which we need to know as a Professional Developer. When we are in college and Programming Beginner we never know or didn't get the opportunity to learn or we learn it but it's not a good practice to apply at professional world. This post will help you find your basic questions and tips to write a professional code.

Before we start let me share two important Mantras: 
"Never trust end users"
"You are responsible for your code"

Tip 1.
#include <iostream>                                    // 1  
using namespace std;                                    // 2  

int main(int argc, const char * argv[]) {      // 3 
     cout << "I'm a Programmer";                // 4 
    return 0;                                                    // 5 

Let me explain you the code.

Line 1: #include <iostream> 
Line beginning with a hash sign (#) are preprocessor directives which instructs the preprocessor to include a standard C++ code, known as header. Here, iostream has been included to allows our code to perform standard input and output operations.

Thinking, What's preprocessor? Just go though this image.

Line 2: using namespace std;
A namespace defines a new scope. They provide a way to avoid name collisions (of variables, types, classes or functions) without some of the restrictions imposed by the use of classes, and without the inconvenience of handling nested classes. 

std namespace is declared in iostream.

I shall always recommend to write Line 4 as std:cout << "I'm a Programmer"; in place of declaring namespace at top.

Why? Suppose there are two variables with same variable name in two separate namespace. Now, if you include both of those using "using". At the time of implementation section it's confusing which variable will be included which may lead to un expected results.

"Namespaces are a powerful addition to an already powerful language, giving the programmer more flexibility, provided he knows how to take advantage of it."

Line 3: int main(int argc, const char * argv[])
When our program will start executing OS will call main method to start it's operation. 
We can recevice paramter to our code. Say our program is complilted and output file name is DemoCode.

Now if we run our code like this:
$ DemoCode India USA UK
argc will give 4 as number of arguments and argv array will have 4 arguments, DemoCode, India, USA and UK.

Line 4: cout << "I'm a Programmer";
It's a way to print a message in Console/output stream.

Line 5: return 0; or return EXIT_SUCCESS;
Once a program has a successful execution it return 0 or use macro EXIT_SUCESS to OS. Otherwise, we can return 1 or EXIT_FAILURE macro which denotes execution failed.
Value of EXIT_SUCCESS and EXIT_FAILURE are declared in header <cstdlib>

Tip 2: 
Comma operator ( , )

For example:
int b;
int a = (b=5,b+2);

In this code, second line first the value 5 will be assigned to b after that 2 will be added to b and last it will be assigned to a. So, a will be 7.

Read More:

Tip 3:


#define [identifier name] [value]
Macro is familiar word for Beginners and a common use most of you may have seen:

#define M_PI 3.14159                                // Approx. value of PI used

float radious = 25.0; 

float circumference = 2 * M_PI * radious;
Read More:

More will be updated soon....


  1. I am a newbie in the world of programming with c++ and I found your tips really helpful. C++ tutorial in urdu

  2. I like the diagrams used to explain the programming. That's what I'm trying to implement in my C++ Website to cater for beginners. Check out my website

  3. This blog awesome and i learn a lot about programming from here.The best thing about this blog is that you doing from beginning to experts level.

    Love from


  4. Thanks for sharing the very useful info about clanguage and please keep updating........

  5. Nice tutorial. Thanks for sharing the valuable info about c Training. it’s really helpful. Who want to learn c language this blog most helpful. Keep sharing on updated tutorials…..

  6. It is very common to find technical issues while using Brother Printer and touch to resolve that. Therefore, you should talk to the technicians at 0800-090-3240 to get the correct solution to that. Visit more information Brother Printer Contact Number UK

  7. Nice blog!! If you need any technical issues just call our Bullguard Support Number UK @0808-238-7544 Bullguard Phone Number UK

  8. | | Norton setup product key, install Norton | activation your product. 1844-516-0689 Download & Install Norton antivirus Product Visit activation website . Norton Setup Help & Norton Customer support will help you resolve any Malware/virus related issues remotely Call Toll Free Number + 1844-516-0689.For any help regarding Norton Antivirus you can directly call on Norton Antivirus Phone Number + 1844-516-0689.Toll-Free to get instant solution 1844-516-0689.Call us at ourNorton 360 by Symantec Helpline Number+ experience the quick and Number+ 1844-516-0689. + 1844-516-0689. l l norton activation key setup l.....

  9. Nice Blog! If you need Software related solution then calls at team …Read More.

  10. Thank for sharing this information about Bullguard. There are so many things that bother Bullguard users and this is one of them. However, users can find solution for other issues on Bullguard Phone Number UK, where I am working 24/7 with my team of technicians.

  11. Web services are client and server applications that communicate over the World Wide Web’s (WWW) HyperText Transfer Protocol (HTTP). Web services provide a standard means of inter operating between software applications running on a variety of platforms and frameworks. Web Design Services

  12. Thank you for sharing such valuable and helpful information and knowledge! This gives us more insights and inspiration. Looking forward to seeing more updates from you.

    Melbourne Web Developer