Basic C program structure
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
- 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'
- 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
May be interested
- Graph data structure (Graph)a graph (graph) is a form of visual representation of a set of objects in which pairs of objects are connected by links. interconnected objects are represented by points called vertices, and links that connect vertices are called edges.
- What is Silo Structure? Advantages and disadvantages of silos and effective alternativeseveryone knows that a properly structured website is good for both users and seo. silo structure is one of many ways that seo experts recommend people to apply for their website.
- PHP syntaxbefore starting programming in any language, the basic syntax and program structure is very important. this chapter introduces you to the basic php syntax, including: php tags, comments, print commands, echo commands, and two print and echo commands.
- How to Create a Basic Laptop Design in the Solidworks CAD Programhave you ever wondered how 3d models are designed and wanted to try to model yourself? this article will teach you the basic skills needed to model a basic laptop design as well as many other shapes open the solidworks program.
- Hash Table data structurethe hash table data structure is a data structure that stores data in a federated manner. in hash table, data is stored in array format, in which data values have their own index values. accessing data becomes faster if we know the index of the data to find.
- Assign Structure to Diagram in Visio 2010 using Containerin the following article, we will learn more about the concept and usage of the container in the process of adding structure to diagram in the microsoft visio 2010 application. in essence, the container is the most dynamic component. , can surround and contain the remaining relevant components ...
- How to Implement a Stack Data Structure in C++a stack is a basic data structure that is commonly used throughout computer science. for example, a stack is utilized by your web browser to remember the last few pages you were on. developers and programmers should be very familiar with...
- Data structure in C / C ++struct in c / c ++ arrays in c / c ++ allow you to define several types of variables that can hold the values of several members of the same data type. but the structure is another type of data in the c / c ++ programming language, which allows you to combine other types of data.
- Structure (Struct) in C programmingarrays in c allow you to define several types of variables that can hold the values of several components of the same type. but the structure is another type of data in the c programming language, which allows you to combine other types of data.
- What is URL? Structure of the URLwhat exactly is a url, what is its structure and composition? this article will give you an overview of urls and its structure.