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.




