Learn to Write Your First C Program – Print Hello Computer – MPS


Learn to Write Your First C Program – Print Hello Computer.

This class outlines the easy steps to write your first C program. You will study what the basic elements that make it work are.

Table of Content

  1. C Program Coding Snippet
  2. Anatomy of the C Program
    1. #include<stdio.h>
    2. int main()
    3. printf()
    4. getchar()
    5. return(0)
    6. The curly braces
  3. Execute C Program

For this visit:  Here

Learn to Write Your First C Program

First C Program

1. C Program Coding Snippet

Below is the C program coding snippet which prints “Hello Computer” on the console. You can use any textual content editor to write this code. But we advocate and use Codeblocks to create, compile, and execute any C program.

#embrace<stdio.h>

int fundamental()

    printf("Hello Computer");
    getchar();
    return(0);

2. Anatomy of the C Program

We will now see what each particular person line in the above code means.

2.1. #embrace<stdio.h>

In the large mind of C, there are some pre-outlined directions to assist customers execute instructions quicker. One instance of that is the “printf” instruction, which we’ll see quickly. There are particular libraries in C that include data of those directions. Therefore, “#include<stdio.h>” tells the pc to embrace the knowledge of those pre-outlined directions to be able to use them in your packages. “stdio” stands for “standard input-output.”

Note: You can observe what occurs if you do not write this line. It will present an error that the perform “printf” is not outlined. It is as a result of the compiler does not know what it means until you present the header file “#include<stdio.h>” which has its definition.

2.2. int fundamental()

Every C program has a set of directions to be executed. We often write them contained in the physique of the primary() perform. It is the entry level routine for all packages to start execution. From the primary perform, we name all different capabilities to carry out a set of duties. So, there has to be a “main” perform in a C program.

In C programming, the primary at all times returns an integer kind worth. The “int” earlier than the primary represents the kind of worth returned.

A C program also can have consumer-outlined capabilities which we’ll cowl in the later tutorials. However, in C programming, utilizing the “main” is obligatory.

Note: You might have observed that after each perform, we give parentheses (). It is as a result of while calling, this system can pass a set of values or parameters to it. They additionally ship again information utilizing the “return” assertion. If there is nothing to return, then we might specify the 0 as a return worth or not use it in any respect.

2.3. printf()

It is a pre-outlined perform in C that tells the pc to show the textual content as it is. It helps the compiler to differentiate between command and precise textual content supposed for printing. The textual content contained in the parentheses ought to seem as it is on the display screen

Note: In the printf() perform, precise textual content to be displayed ought to be enclosed in double inverted commas “_.” Something like printf(“Hello Computer”).

2.4 getchar()

It is a C enter perform which makes this system wait till the consumer presses a key.

2.5. return(0)

It represents the return code of the primary() perform. A non-zero worth means error whereas the zero signifies this system will get executed efficiently.

In our instance, we return a zero worth which evaluates to success.

2.6. The curly braces

The curly brackets allow us to create a number of items of code in a C program.

They outline the boundaries of a perform such as the primary() right here and contains directions that may get executed in the C program.

A perform can have a number of nested blocks of code delineating utilizing the curly brackets. Each such part has entry to variables from the dad or mum block, however any of its variables will not be seen from outdoors.

We’ll present an in depth description of the variable scope in the subsequent lessons.

3. Execute Your First C Program

Now that we’ve efficiently understood what each line means. Let us kind this code on our newly setup IDE and Run it.

When you kind this code and run, you must see one thing like this.

Use Codeblocks to write your first C program

Now click on on the higher inexperienced triangle, and you must see a display screen like this after just a few seconds.

Execute your first C program

Congratulations, You have efficiently written, compiled and run a C program.

Learn to Write Your First C Program – Print Hello Computer

Python  Recommended Post

Learn to Write Your First C Program – Print Hello Computer
Source hyperlink

Have any Question or Comment?

Leave a Reply

Your email address will not be published. Required fields are marked *

Categories

You have successfully subscribed to myprogrammingschool

There was an error while trying to send your request. Please try again.

My Programming School will use the information you provide on this form to be in touch with you and to provide updates and marketing.