# First C Program Let's command your computer

Let’s start with the simplest possible C program and use it to understand the basics structure of C program.

Tasks

  1. Change the output with your name.

Let’s walk through this program and start to see what the different lines are doing:

/* simplest possible C program */
#include <stdio.h>

void main() {
  printf("Hello World");
}
1
2
3
4
5
6
  1. This C program starts with #include <stdio.h>. This line includes the “standard input/output library” into your program. The standard I/O library lets you read input from the keyboard (called “standard in”), write output to the screen (called “standard out”), and so on. It is an extremely useful library. C has a large number of standard libraries like stdio, including string, time and math libraries. A library is simply a package of code that someone else has written to make your life easier.

Some of the Standard library are

<math.h> , <string.h>, <time.h>

  1. The line void main() declares the main function. Every C program must have a function named main somewhere in the code. We will learn more about functions shortly. At run time, program execution starts at the first line of the main function. void means it return nothings to the compiler.

  2. In C, the { and } symbols mark the beginning and end of a block of code. In this case, the block of code making up the main function contains two lines.

  3. The printf statement in C allows you to send output to standard out (for us, the screen).

Tasks

  1. Most of the compiler wants 0 from the program as no error , Change the program to return 0.

Declare main function as integer , and add code return 0; at the end of main function

(adsbygoogle = window.adsbygoogle || []).push({});

# Sections

Let divide the entire program into sections , so it will be easy to remember

# 1. Documentation Section

/* simplest possible C program */
1

The documentation section contains a set of comment including the name of the program other necessary details. Comments are ignored by compiler and are used to provide documentation to people who reads that code. Comments are be giving in C programming in two different ways:

  • Single Line Comment
  • Multi Line Comment
// This is single line comment

/*
This is 
multi line
comment 
*/

1
2
3
4
5
6
7
8

# Tasks :

# 1. Change the comment into Multi line comment.


#include <stdio.h>
1

# 3. Definition Section

Not present , we will use in variables.

# 4. Global Declaration Section

Not present , we will use in variables.

# 5. main() Function Section

void main() {
  printf("Hello World");
}
1
2
3

# 6. Subprogram Section

Not present, we will study in Functions

(adsbygoogle = window.adsbygoogle || []).push({});