c - Can you explain this 'Hello world' program? -


I have just begun learning but I do not understand this part of the code. Can anyone explain each line of code and thanks for what it does! Please tell me what I said instead of saying (thank you in this book) Thanks. Hope you guys can help me

  #include & lt; Stdio.h & gt; Zero zero (zero); Int main (int argc, const char * argv []) {SayHello (); Return 0; } Zero shenlo (zero) {printf ("hello, world! \ N"); }  

I would suggest getting a separate book, because it might tell you Should have been given However, get it!

  #include & lt; Stdio.h & gt;  

In that episode, "Preprocessor" (the part of the compiler that is ready to be compiled) asks to take the contents of the file "stdio.h" in some special part Like this, keep the compiler on top of your source code, and this way, the compiler may know about the function printf below, what is this for logic, and what value (Gives it back after it's finished).

  zero to zero (zero);  

This part is declaring the function. By putting the definition there, you can call the function before writing the implementation. This function tells the "header" to the compiler that there will be a function that gives zero (i.e. nothing). After this is finished, no value is returned, for example, no < Code> int , because nothing has returned from SayHello () ). It does not take any argument, therefore, you can not write SayHello (34) , because it takes zero arguments, i.e. none

  int main (int argc, const char * argv []) {  

This part is the beginning of the "main" function. The main function is where your computer wants to start the program. This is the starting point, there are two arguments in it; The number of arguments ( int argc ) has been passed on the command line (for now) and in the "array" of "strings ( char * )". An array contains a list of the same type of data. Then you may have an "array" of char * if you start your program like this: ./myProgram fish , argv [1] ] contains an array of characters ( char * ) "fish". Do not worry about this part, your book will explain it later.

  SayHello ();  

This part calls the function SayHello () . The title of SayHello is above, but the program below says the actual implementation of the work. SayHello does not take any arguments, and does not return any value ( zero ). The computer temporarily jumps on the SayHello function. When it ends, it returns to the main function where it was left. We will get the actual SayHello definition later.

  0 back;  

The main function returns an integer if everything is ok, back 0 ; That is, the program was resigned.

 } // With the end of the ceremony of zero, hahlo (zero) {// we have already covered this part above printf ("hello, world! \ N") ; }  

This part is the actual work that we have created. One of its goal is to console Hello, world! is printed We complete this by calling the another function defined in the stdio.h file, which we included. His name is printf . It has many different wires (it will be covered later in your book), and prints on the console. Your book will probably cover printf very soon. For now, all this prints a string (you can print it with a format like this: printf ("my number:% d", 34); which option 34 with>% D . For now, just remember that it prints a string. So, after this "Hello World!", A new line ( \ N ). printf a int , but this is only for error retrieval purposes. End of printf After this, call it Lo function, which then ends and returns to main , which ends and returns 0 .

Hope this will tell you well!


Comments

Popular posts from this blog

c++ - Linux and clipboard -

Visual Studio 2005: How to speed up builds when a VSMDI is open? -

booting ubuntu from usb using virtualbox -