Saturday, 5 October 2013

Indentation in C++

Indentation In C++:

In this c tutorial for beginners, we are going to discuss about indentation meaning.

Indentation has come from indent meaning the correct alignment of the code. The order of alignment does not affect the execution of program in any way. Indenting is only done to make the code neat and clean and to get the idea of how the code works and which step is connected to which. It is a good programming practice that you indent your code after writing it. If you do not indent it then we won’t get to know that how the code is working.

Example:

indent meaning

This is a bubble sort program. You can see that the code is unindented.
1.       The int temp=0; is typed one step forward which should have been just below int arr[size].  
2.       Arr[i] is just before the for loop so, in this way you cannot tell that if it is a part of the for loop or not.
3.        The if condition should have been below the for loop which has iterator ‘j’ and its parenthesis are also not at its place.
4.       The starting and ending parenthesis are also not at their place.


indent meaning

This is the indented code of bubble sort algorithm.

Steps for indenting:

  •  First see that the related loops, conditions and statements are correctly aligned and have a connection or not.
  • Then see if there are unnecessary new lines. If there are , then remove them.

Keyboard shortcut keys:

Auto indenting:

For auto indenting, select that part of code which you want to indent and then first click ctrl+K and then ctrl+F.

Key: Ctrl+K, Ctrl+F

Final Words:

In this post of shapes in c, you have learnt the meaning, use and advantages of indenting. In this c tutorial for beginners, we discussed the topic of C++ indentation in detail and each and every aspect of how it can be used and what steps should be kept in mind while indenting one’s code.

0 comments:

Post a Comment