Quick Contact

    Comments and Format specifier in C

    The comments refer to the explanation or description of a particular line in the source code. It helps the programmer or coder to understand the logic of a particular code or program. The comments can also improve the readability of the program. It also ignored by the compiler at the run-time.

    C language comments

    The comments can make a code easier to find the error, and it is the most important part of any code documentation of particular software. The comment also works like annotation in the program or code.

    There are two types of comments in the C programming language, which are given below:

    • Multi-line comment

      The multi-line comment starts with forwarding slash and asterisk and ends with the asterisk forward slash in the program. This comment can apply with more than one line in a particular code to describe the meaning of those lines of code.

      /* ------ text as comment -------- */
    • Example:
      			#include < stdio.h>
      			int main(void) 
      			    /* initialization of the main function 
      			With multiline comment */
      			    printf ("Ram is Good Boy"); 
      			    return 0; 

      Ram is a Good Boy

    • Single line comment

      The single-line comment permits the user to comment only one line at a time in the code or program. This type of comment starts with the // (double slash) in a particular program to describe the meaning of the individual line.

    Format specifier in C programming language

    Format specifier defines the type of printed information or data on the standard output. These specifiers can also use during the input and output process. The compiler can understand the type of data in the input and output operation with the help of a format specifier. Some important types of specifiers are as follows:

    • The minus sign (-) is a format specifier that tells the left alignment in a particular code procedure.
    • The percentile symbol (%) defines the minimum field width after the number. When the particular string is less than the width, then the width will be filled with the spaces via using this format specifier.

    There are some necessary format specifiers given below in the list which are used in the coding for several purposes.

    Format specifier Use of specifier
    1.%% This format specifier is used to print the % character as the output.
    2. %c It is used to the characters according to the requirement of the user.
    3. %d The %d specifier is mainly used for the signed integer.
    4. %e or %E It is used to the scientific notation of floating points.
    5. %f The %f format specifier is used to the float values in the code.
    6. %g or %G
    7. %i It is used to print the integer value of the particular program as per the requirement.
    Use of %c format specifier
    		#include < stdio.h>
    		int main ()
    		char info = 'Z';
    		printf ("%c\n", info);
    		return 0;
    Output: Z
    Another way to use %c format specifier
    		#include < stdio.h>
    		int main ()
    		int data = 90;
    		printf ("%c\n", data);
    		return 0;
    Output: Z

    Copyright 1999- Ducat Creative, All rights reserved.

    Anda bisa mendapatkan server slot online resmi dan terpercaya tentu saja di sini. Sebagai salah satu provider yang menyediakan banyak pilihan permainan.