Basic C program structure
Before we study the blocks that make up a C program, first look at a sample C program.
Before we study the blocks that make up a C program, first look at a sample C program.
Program C: Hello World
A C program includes the following:
Preprocessing orders
Functions
Variables
Commands and expressions
Comments
First look at the simple code that will print the screen two words "Hello World":
#include int main () { /* Day la chuong trinh C dau tien */ printf ( "Hello, World! n" ); return 0 ; }
Please see the parts of the program above:
- The first line of the #include program is a preprocessor command, prompting the C compiler to add the stdio.h file before compiling.
- The next line int main () is the main function, where the program starts.
- The next line /*.*/ is the comment line that is ignored by the compiler and is used to add comments to the program. This is called the comment section of the program.
- The next line printf (.) is another function of the C language, which prints the message "Hello, World!" displayed on the screen.
- The next line return 0 ; end the main function and return the value 0.
Compile & Implement Program C
1. If you use Dev-C ++, Microsoft Visual Studio, . then open the application, go to File, select New to create a new source file. Then copy the above code into this new source file. With Dev-C ++, you use Complile & Run to compile and run the program. With Microsoft Visual Studio, you do the same and then use Build to compile and execute.
2. If you use the command prompt to compile, follow these steps:
- Open an editor and add the above line of code.
- Save the file as hello.c
- Open the command prompt and go to the file storage directory.
- Prepare gcc hello.c and press Enter to compile the above line of code.
- If there is no error on the above code, the command prompt will take you to the next line and create an executable a.out file.
- Now, edit a.out to implement this program.
- You should now see the words " Hello, World " printed on the screen.
$ gcc hello . c $ ./ a . out Hello , World !
Make sure the gcc compiler is installed on your computer and that you are running it in the directory containing the source file hello.c.
According to Tutorialspoint
Previous article: Instructions for installing C
Next lesson: Basic syntax of C programming
You should read it
- C # program structure
- How to 'survive' with the stress of learning programming
- Bookmark a few tricks to help you master a programming language
- Bookmark 5 best Python programming learning websites
- 11 tips for learning Python for 'newbie'
- The Wonders of Learning How To Program And Its Benefits To Your Business
- AI engineer Facebook talks about deep learning, new programming languages and hardware for artificial intelligence
- Top 20 free programming learning websites need to bookmark immediately!
- Prepare for your baby: 5 ways to get children interested in programming
- Top 6 outstanding online learning trends in 2018
- Top 5 best programming languages for kids today
- Google researchers for gaming AI to improve enhanced learning ability
Maybe you are interested
Nvidia just caused the 'blue screen of death' error for Windows Trees also know how to cry in pain when their flowers are cut off from their branches Blue screen of death BSOD error codes list How to Speak American English How to Change Windows Startup Sound Did you know: In addition to the blue screen, does Windows also have a 'dead' green screen?