C++ Programming Style and Structure

Good morning, Good Afternoon and Good Evening accordingly at whatever time you visit this blog. After a pretty promising article on the C++ language, Punit Sharma is back again with another article which aims to familiarize you with the programming styles of C++ and what changes have been made in the syntax which makes it different from C programming language. Just a little prerequisite is getting familiar with some programming terms. Although, every term will be explained in brief. But it’s good to listen to what you are acquainted with.

Statement

Starting with the atomic element of any programming language i.e a statement. A sentence in human form of communication represents a statement in a programming language. We write statements in order to make the compiler understand our logic to the real life problem. To be precise, we are expressing ourselves in front of machine via statements and compiler is something which makes the machine understand our statements. Statements might contain mathematical expressions, initializations or assignment , declarations and many more which we will be dealing with later.

Library

A library is a set of predefined, rather precompiled codes which are bound together in a single unit for reusability purpose i.e they can be extended  in any user defined program in order to provide a set of codes dedicated for a specific purpose. The purpose might be graphics implementation, threading implementation, audio implementation and many more. C++ also comes along with an inbuilt vast standard library i.e C++ standard library. The very much used common library is the iostream which is meant for input and output from/to any media or any device respectively.

Functions or Modules

In C++, a block or set of statements may be defined in a manner such that they serve a specific purpose and can be called at any point of a user built program in order to accomplish a sub-task. Every C++ program must have a main function. Whenever a C++ program is executed, the entry point of execution is the main function. In other words, it is the driver function of the whole program and the part of code which contains the main function is the driver code. Custom or user defined functions may also be created in order to achieve a certain task. ‘Functions’ will definitely be a point of discussions in the upcoming articles. For now, we leave it up till here.

The basic prototype of functions in C++

<Return Type> <Function Name> (<parameter type> <parameter name>)    // This is function signature
{

    // function body
}

There you go, Congratulations… You learnt something new… And obviously, we will be saying hello to the world via a sample program.

#include <iostream>

int main()
{
    std::cout << "Hello World. I am from theoryofprogramming.com";
    
    return 0;
}

Up till what we have learnt now, let’s draw some inferences regarding the above code

iostream – Guess what it is?? It’s the header available under C++ standard library that defines the standard input/output streams.

int main() – A function just discussed a few lines ago. And you can see, it draws the prototype exactly which I mentioned above.

int main()    ------->  function signature
{    ---------- Function Body starts here -------------

    std::cout << "Hello World. I am from theoryofprogramming.com";
    
    return 0;
    ----------- Function Body ends here --------------

}

main() also takes some parameters as a variation which we will be dealing with later… A complete article over main() will be there as we proceed further. And obviously lines 1, 3, 5 and 7, all of these are statements

Basically, this was a complete analysis of whatever we learnt in the whole article. This article is dedicated to the ones who do not know the ‘P’ of programming or ‘C’ of coding and have a curiosity of knowing about what is programming. Any expert comments are appreciated in order to make the article more friendly to the beginners.

Leave a Reply