Post: C Programming #1 Hello World
06-27-2017, 03:46 PM #1
(adsbygoogle = window.adsbygoogle || []).push({}); Sup boi this is my first C programming Tut. C is a very good language to learn and if you want to learn C++ I recommend learning C first. These tuts will not cover the history or anything like that it will only cover the code so before we begin here is a good resource that is good to use for references do not READ it work it what i mean by that is write out all the examples and try to do the exercises*C.*

C Programming Language, 2nd Edition*

So lets begin so in this tut i will go over a simple program which is the Hello world program to make this we use the code below.

int main(){
* *printf("Hello World);
* *getchar();
}

The above code will print the text Hello World to the console and then will wait till the user has pressed ENTER or clicked the x to close the program.

So the first line that will be executed is int main(){} this is a function we use functions to store all of our code in unless you want code to be global. Everything between the {} are called statements. Statements should usually end with ; but sometimes do not. If you have have some previous programming knowledge in C# you might of heard of a method or in vb.net you might of heard of sub routines they are just functions with different names don't ask why I have no idea why.

The next line that will be executed is printf("Hello World"); this will print hello world to the console as printf is used to print characters to the console.

The last line that will be executed is getchar(); without it the program will open and close really fast so we use getchar(); so it will wait until we press ENTER or click the x to close the program.

so that's my first tut done i know its really short but there is no point in learning a lot of stuff and then having to learn it all the next day because you cant remember it.*

Exercises:
make your own program using printf and getchar make the output be you name and age and make sure they are commented // <- that's a comment.*

If you want more just say Smile
03-15-2018, 09:50 AM #2
MrRa1n
League Champion
The main method you have declared is of type int but does not return a value. Try using void instead or add return 0; to the end of the method. Also, instead of using getchar(), just give main a couple of parameters to read command line arguments. Lastly, you are calling the printf() function. This is included in the C standard library, so add #include <stdio> to the very start of your code.

An example below:

    

#include <stdio.h>

int main(int argc, char **argv)
{
printf("Hello, World!\n");

return 0;
}

Last edited by MrRa1n ; 03-15-2018 at 09:59 AM.

The following user thanked MrRa1n for this useful post:

Algebra
09-15-2018, 05:40 AM #3
Originally posted by Zone1337 View Post


int main(){
* *printf("Hello World);
* *getchar();
}



You can also add a do while loop if you want to make the program infinitely run until the user exits...

    
int main(){
* *do {
* *printf("Hello World);
* *getchar();
* *} while (1)
* *return 0;
}
12-03-2018, 01:00 PM #4
Algebra
[move]mov eax, 69[/move]
Originally posted by Zone1337 View Post


Bisual Vasics
02-06-2024, 05:36 AM #5
gregon
Rookie
Programming is a very interesting science. I really enjoy studying it, although I have problems with some tasks. Then I immediately take You must login or register to view this content.. With them, I am confident that the work will be done competently and in a language I understand. And I can quickly understand this topic.

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo