Sep 19, 2014

How a setw() function works

                   setw() function is used to create the specific width of empty space or empty gap space like tab, in between the sentences or in function headings.The function header library that is used for this function is "iomanip".  

Let us have a look through an example :
   


                     Here the cout statement first prints the hello word and then it leaves the space of 10 characters. After that we have again an another word to be printed. So the compiler checks the no of characters (sizeof the word) and will initialize the remaining space for the gap, printing the word starting from the last space of gap right to left. If the word will have greater number of characters than the size specified for the gap then it starts printing next after the first word without space.

 
                         cout<<"hello"<<setw(10)<<"world";

 Output :
 

                         cout<<"hello"<<setw(4)<<"world";

                 Here the size of word "world" is greater than the size specified for the empty width.

  Output :












Filed under  | 

Sep 15, 2014

Parameters...Arguments...Are they represent same meaning or differ??

Parameters...Arguments...Are they represent same meaning or differ??

          We will come across these words when we use Functions, at the time of Function call, Function declaration and Function definiton.In most of the programs we will use functions as they are easy to use,reduce the complexicity and can understand the program easily.Ofcourse using functions increase the running time of the program, but without these it is difficult to write the code for the program having a hundred of steps (statements).

Lets look at the example :


Parameters :


                      The names that are written in the function declaration or function definition are calles parameters. These are also called as Formal Arguments”

⦁ In the above example a, b are parameters.




Actual Arguments:      
                      The values that are passed to the variables at the time of function call are called Arguments. These are also called as “Actual Arguments”.


⦁ In the above example 3, 4 are arguments.























Filed under  | 

How a .EXE file is created

How the program is converted to machine code? What are the steps involved in it?

                        First of all, The code has to be written in any text editor and save the file with an extension of ".c" for c program and ".cpp" for the C++ programs. The name of the file can be anything (it doesn't matter), but the file extension is required. Now the program is ready to convert it into a language that machine can understand (also for the compiler to execute).

Generally in any compiler,the process involves in 3 steps:

1.Preprocessing
2.Compiling
3.Linking

Preprocessing :
                     First, The program is given to the preprocessor that obeys(look at) the commands which starts with "#", generally called as "Directives". It will add the extra code that is required for the directives to execute. It like a editor that add the things to the program and make the modifications. Infact the preprocessor is integrated with the compiler, so we probably even notice it at work.
Compiling :
                  Now the modified program goes to the compiler and it converts into the machine instructions called "ObjectCode". After compiling, the object file is created (.obj file). The program is not ready to run yet.


Linking :                
                 Then after, Linker combines the object code produced by the compiler to yield the complete executable program with an extra additional code added. The extra code that was added here includes the addition of library functions like printf etc. Finally after this, an executable file is created, that is ready to run the program. Probably this linking step is automated by the compiler
                The commands necessary to compile and link are vary for the one operating systems to another.






Filed under  |