First Program in C - Structure, Values and Architecture



You have learned from our previous posts about why should you learn it and have got an introduction to C, its character set, constants, variables, and keywords.

If you haven't, I strongly suggest checking out the following links:

1.) 
https://collegeintegral.blogspot.com/2022/06/introduction-to-c-why-should-you-learn.html

2.)
https://collegeintegral.blogspot.com/2022/06/introduction-to-c-constants-variables.html

With that out of the way let's get started with the first program in C
As customary let's create a Hello College Integral code and run it.

#include <stdio.h> 

int main()
{ 
    printf("Hello College Integral");
    return 0;
} 

To run this code either you have to set up your windows-based GCC compiler and use it or make use of any external ide or just run it online on an online compiler, more on this later.

In this code, you can see that there is a line #include <stdio.h>
this line is used to "include" or import the library "stdio.h".

"stdio" stands for standard input-output( "st" stands for standard and "io" stands for input-output)
we shall learn more about this and other important C libraries later.

then there is main(), main() is a very crucial part of any program and holds utmost importance as it is the only function that is absolutely needed in any program.

printf() is another important function that is used to print whatever is provided to it.
we shall also learn about main(), and printf() in the next post, and for now just understand what these do and learn the syntax.

The syntax and the basic rules of a C program:

1.) Each line or command or statement or instruction( whatever you call it) must be written in a separate line.

2.) The general order of these said lines should be the one in which they are to be executed (to run).

3.) blank spaces can be used anywhere in the program to increase readability (make it easier to read) but this must not be the case for keywords, constants, and variables.

4.) All instructions must be in small cases.

5.) C provides a free form in the writing of a program, meaning that when you write a C program it is not specified to you where the statement shall start in any given line.

6.) all statements must end with a semicolon (;). ";" is what you would call a statement terminator meaning it marks the end of a statement in C.

Comments in C:

Any programming language regardless of its use regardless of its type (procedural or object-oriented) has comments available for use and there are multiple reasons for that.

But first, let's understand how to put comments in a C code or C program.
In C comments should be enclosed in /* …comment here...*/

the "…comment here..." that I have put in between  /* */ will be the comment.

Comments are a necessity.
Why?

To understand the importance of Comments, let's understand a scenario.

You are working with a team of programmers at your job and have been tasked to work on a large code, you must first understand the thousand lines of code written earlier, then you have to discuss with your team what you need to do now, delegate tasks and get to work.

But how will you understand those thousands of lines of code fast?

yes, that's right by the use of comments,
you see comments can be provided by the earlier programmer depicting the variable name and the reason behind those names, what does the function do? or just some basic understanding or logic that needed to be written, all of this is done by comments and hence their requirement.

Post a Comment

Previous Post Next Post