My First C Program


📝 Blog Outline:
Introduction
Why I Chose to Learn C
My First C Program: Code Breakdown
Reflections and What’s Next
1. Introduction
As a 16-year-old high school student, I recently began exploring programming with the goal of majoring in electronic engineering in university. Today, I want to share the story of my very first C program — a small but meaningful milestone on my learning journey.
2. Why I Chose to Learn C
Many people might ask: Why start with C? Isn’t it hard? Actually, that’s exactly why I chose it. C is the foundation of many modern programming languages and is widely used in embedded systems, which are essential in electronic engineering. Learning C will help me understand how hardware interacts with software at a deeper level.
3. My First C Program: Code Breakdown
Here is the first C program I wrote:
Let me explain each part of it:
• int main () A complete program must have a main function. The program always starts executing from the main function. ‘int’ reprensents the output is an integer. Similarly, we can also use ‘short‘ to express a small integer, ‘long‘ as a big integer etc.
• There is a pair of curly braces after main(), and the part within the curly braces is called the function body. Generally, the function body is composed of a "declaration part" and an "execution part". The declaration part is used to define data types (e.g. float, double, int, etc.); the execution part gives operation instructions, and the execution part is composed of several statements.
•Especially, each statement must end with a semicolon ';'. '\n' is to 'carriage return and line feed'. '%f' is a format character for outputting a real number. When executed, the value of the variable outside the double quotes replaces '%f' and is output in real number format. The '%f' format only provides 6 digits after the decimal point.
• #include <math.h> and #include <stdio.h>: These are library headers that allow us to use math functions like sin() and print results with printf().
• float x; ‘x’ is a user-defined variable, and 'float' specifies that x is a floating point variable (a decimal number with six decimal places retained).
• x = sin(30); assigns the sine of 30 to variable x.
• printf("%f\n", x); prints the value of x as the output.
• return 0; is meant to end the program—it is a means to test the program.
4. Reflections and What’s Next
Writing my first C program was a great experience. Even though the code was short and I made a few beginner mistakes, it helped me understand the basic structure of a C program, how libraries work, and how to debug simple errors.
Moving forward, I want to write more programs that involve logic, user input, and maybe even interact with hardware like sensors. C might be tough, but I’m excited about the challenge — and this is just the beginning of my journey in electronic engineering.
References
Tan, H. Q., Zhang, J. W., & Tang, Y. Y. (2023). C Programming Language Tutorial (2nd ed.). Higher Education Press.
Subscribe to my newsletter
Read articles from Tongjia Jiang directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
