Structure of C --Basics
;
Did you think the ; was just a random character I put there by accident? WRONG!!! That ; goes after every sentence of code in C...except for while and if statements I will talk about later. Think of the ; as a period at the end of each sentence. Example:
printf("Hello World\n");
See the ; at the end of that line? If you don't add that at the end, it will make a syntax error. You may now ask me: what is printf?
printf("Hello World\n");
See the ; at the end of that line? If you don't add that at the end, it will make a syntax error. You may now ask me: what is printf?
printf("Hello\n");
The printf function prints some text on the user interface.
Example:
printf("Hello world\n");
In the quotation marks is what you want to show on the screen. When you do this, this will pop up on the screen:
Hello world
_ <---Cursor
You may ask me, why is the cursor there? And why is there a \n that doesn't show up on the interface? That \n tells the cursor to move down one. Say you did two printf commands without the \n. This is the result:
printf("Hello world");
printf("Hello world");
Result:
Hello worldHello world_
Notice where the cursor is. That is why the \n is important.
Example:
printf("Hello world\n");
In the quotation marks is what you want to show on the screen. When you do this, this will pop up on the screen:
Hello world
_ <---Cursor
You may ask me, why is the cursor there? And why is there a \n that doesn't show up on the interface? That \n tells the cursor to move down one. Say you did two printf commands without the \n. This is the result:
printf("Hello world");
printf("Hello world");
Result:
Hello worldHello world_
Notice where the cursor is. That is why the \n is important.