Our First Code

First things first. Your text must be courier or courier new. When we write code, we are creating functions to run tasks that we specify. All functions require a type and a title, however we must always have a main function. We will start with int main(). The parentheses will be empty for now. Every function will be followed by brackets {} with the operands contained within the brackets. Every function must return something of the same type as the function. For example, int main(){ return 0;}{   // these two dashes represent that this is a comment. It is only valid for one line of code. The function that must be present in all codes is (int,char, string) main(){}. Ok lets print something to our console.

#include <stdio.h>
#include <stdlib.h>
int main() {
/* longer comments are represented like this and they can last for many lines and at the
end of a comment you close with */

printf(“Hello World!\n”);   /*printf is an operand which allows us to print
data and text to the console. the \n is for creating a new line at the end of the text. 
you can also use \t to tab after the text. This can be important for organizing
the output of your code.*/

return 0;  //always return to a value of the same type as the function.
}

Conclusion

Ok let’s recap. You will notice every line of code contains a “;” at the end. This signifies the end of a line. Over 99% of the time you will miss one so make sure that you double check. “\n” represents new line it is equivalent to pressing return when typing a document. \n is great for organizing data printed to the console. “/t” is equivalent to pressing the tab key in the document.

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s