Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Structure of the C-Program | Introduction
C Basics

Structure of the C-ProgramStructure of the C-Program

Programs written in the C language are block-structured, often referred to as "building blocks." Here's a basic program that displays the message "Hello, c<>definity!" on the screen:

Please, reload the page if you have any problems with runnable examples

c

Main.c

The double forward slashes // indicate a comment. Comments don't influence the behavior of your program. They're meant for human readers, not the computer. There are two types of comments in C:

Include Directive

The #include is a preprocessor directive that incorporates the "stdio.h" file into our program. This directive should be placed at the beginning, before the main program (main) kicks off.

Stdio Header File

The "stdio.h" file contains the printf() function. By including it, we're simply adding the capability to display text on the screen to our program. Many C programs don't inherently have access to I/O (input/output) functions or others from the "stdio.h" library. That's why we need to explicitly bring it in using the #include directive.

Note

A guiding principle in C is to keep your program lean, avoiding the inclusion of unnecessary functions.

Main Function

This is the primary function where the heart of your program resides. In this example, it's tasked with displaying text on the screen. The name of this function, main, is reserved in C, and there should only be one main function in each program. Think of the main function as the engine of a car; it's essential. We'll delve deeper into functions as this course progresses.

Brackets and Scope

You'll encounter plenty of curly braces { } in C and other C-derived languages. It's a hallmark of the language.

These braces define blocks of code, much like bricks make up a wall. Here's a way to enhance our sample program:

c

Main.c

Each block produces its respective output.

You can create as many main functions as you want in the C program.

Виберіть правильну відповідь

Все було зрозуміло?

Секція 1. Розділ 1
course content

Зміст курсу

C Basics

Structure of the C-ProgramStructure of the C-Program

Programs written in the C language are block-structured, often referred to as "building blocks." Here's a basic program that displays the message "Hello, c<>definity!" on the screen:

Please, reload the page if you have any problems with runnable examples

c

Main.c

The double forward slashes // indicate a comment. Comments don't influence the behavior of your program. They're meant for human readers, not the computer. There are two types of comments in C:

Include Directive

The #include is a preprocessor directive that incorporates the "stdio.h" file into our program. This directive should be placed at the beginning, before the main program (main) kicks off.

Stdio Header File

The "stdio.h" file contains the printf() function. By including it, we're simply adding the capability to display text on the screen to our program. Many C programs don't inherently have access to I/O (input/output) functions or others from the "stdio.h" library. That's why we need to explicitly bring it in using the #include directive.

Note

A guiding principle in C is to keep your program lean, avoiding the inclusion of unnecessary functions.

Main Function

This is the primary function where the heart of your program resides. In this example, it's tasked with displaying text on the screen. The name of this function, main, is reserved in C, and there should only be one main function in each program. Think of the main function as the engine of a car; it's essential. We'll delve deeper into functions as this course progresses.

Brackets and Scope

You'll encounter plenty of curly braces { } in C and other C-derived languages. It's a hallmark of the language.

These braces define blocks of code, much like bricks make up a wall. Here's a way to enhance our sample program:

c

Main.c

Each block produces its respective output.

You can create as many main functions as you want in the C program.

Виберіть правильну відповідь

Все було зрозуміло?

Секція 1. Розділ 1
some-alt