First C Program
×


First C Program

143

The only way to Learn a new Programming Language is by writing programs in it.

C program consists of many components, such as Header files, Main functions, Variable declaration, Statements, Comments, Functions, Return type, and Standard input/output function.

C Program Structure

First C Program

Explanation of Program

#include<stdio.h>
int main()
{
printf("hello C language");
return 0;
}

1Preprocessor Directive: A preprocessor directive in C is like a set of instructions that tells the compiler to do certain things before the actual compilation process begins It starts with a # symbol and is processed before the code is compiled.

2#include<stdio.h>: This line includes the standard library stdio, which contains printf and scanf that is used for input and output.

3int main(): This is the main function where the program is executed. It returns an integer 0 to indicate successful execution.

4printf: This line prints "Hello C programming language". It is used to print formatted output to standard output. The "printf" function helps you show text, numbers, and other kinds of information on the screen.

5return 0: It indicates the successful execution of the program.

Essential Elements in the C Program

1Header Files:

Function, Variable, and macro declarations in other source files using a preprocessor directive.

Header files have '.h' extensions.

It offers a method for distributing declarations among many source files.


2Main Functions:

The main function is a special function that acts as the starting point for running a program.

The operating system starts running the program by calling the main() function.

Main function returns an integer value (usually 0) to indicate whether the program executed successfully.


3Variable Declaration:

Variable declaration in C is when you specify what type of data a variable will hold and give it a name.

This statement specifies the type of data that the variable will contain.

Additionally, it provides information to the compiler regarding the data type the variable will handle.

It tells the compiler the kind of data the variable will contain.

For example: int, float, char.


4Comments:

Comments in the code give details of the program but are not considered by the compiler when it compiles the program.

Comments improve code readability.

In C, you can write two kinds of comments.

  • Single-line comment: Single-line comments begin with // and continue until the end of the line.

  • Multiline comments: In C, you can create multiline comments using /* to start and */ to end them. These comments are useful for longer explanations or comments that span multiple lines of code.

5Return type:

The type of value a function will give back to the program that calls is determined by its return type.

When you define a function, you mention the return type before its name.


6Standard Input/Output Function:

Standard Input/Output functions belong to the standard Input/output library.

It includes ways to interact with users.

Some of the standard input/output functions are as follows.

printf(), scanf(), getchar(), putchar(), gets(), puts(), fgets(), fputs().



Best WordPress Hosting


Share:


Discount Coupons

Get a .COM for just $6.98

Secure Domain for a Mini Price



Leave a Reply


Comments
    Waiting for your comments