Broad Network


Basic Syntax in the C Language

Foreword: The statement, comments and block are explained in this tutorial.

By: Chrysanthus Date Published: 31 May 2024

Introduction

The statement, comments and block are explained in this tutorial.

Statement
A typical statement in C, is some code that ends with a semicolon. The following two lines are two statements:

        printf ("Hello World!\n");
        return 0;

Comments
A programmer should have comments in his/her code. Comments are not executed. Comments are to remind the programmer, later, of why he/she typed a particular piece of code. There are two types of comments in C: single-line comment and multiple-lines comment. A single-line comment can only be in one line; something like:

        // This is a single-line comment.

A single-line comment begins with a double forward slash. For a single-line comment, everything to the right of the comment is not executed.

A multiple-lines comment begins with /* and ends with */ . An example is:

/* This is a multiple-lines comment. It can be of any length, and
you can put whatever you want here. */

A multiple-lines comment spans more than one line. The opening delimiter is a forward slash and asterisk. The closing delimiter is an asterisk and then forward slash.

Block
A block in C source code is a set of statements delimited by the braces, { and }. Many blocks are preceded by an expression. Such preceding expression should be considered as part of the block code. In the following source code, there is the expression, "int main()" followed by lines (statements) in curly brackets (braces). The braces and the delimited content, is an example of a block.

    #include <stdio.h>
    int main()
    {
        printf ("Hello World!\n");
        return 0;
    }

Conclusion
In this tutorial, the statement, comments and block have been explained.



Related Links

More Related Links

Cousins

BACK NEXT

Comments