Simple C Program

Note: The C language doesn't use line numbers. They are for reference purposes only and are not a part of the code.

Below is a brief overview of some of the basic parts of a C program. These will all be discussed in detail later in the class.

Line 1
#include is a preprocessor directive that includes the contents of a header file (stdio.h) in this source file.

Line 3
#define is a preprocessor directive used here to create a text substitution label. Anywhere below this line where the text "PI" is encountered, it will be replaced with "3.14159".

Line 5-13
This is the main() function. Every C program must have one, and only one main() function. This is where your application code resides and is the first thing to run after the C Runtime Environment setup code completes.

Line 7
Here, two floating point variables are declared. In C, a variable must be declared before it can be used.

Line 9
This line is a comment.

Line 10
This line is an assignment statement.

Line 11
This line is also an assignment statement whose value is that of the arithmetic expression.

Line 12
This is a call to the printf() function. It prints the value of the variable area in a terminal window on a PC or in the UART1I/O window (if configured) when using the simulator in MPLAB® X IDE. (We will make extensive use of this feature in this class.)

© 2024 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.