Saturday, July 4, 2020

Chapter-2(part-1)

C Tokens:

The smallest unit of a program and compiler identifies them as a token.

Below are the types of Tokens available in C language.

  1. Keywords: These are the special words that have been reserved by the compiler and has special meaning for each word.
  2. Variables or Identifier: These are the name given by the programmer for a memory location to store a value.
  3. Constants: these are assigned to the variables.
  4. Operators: These are different types of expressions that are used in C.
  5. Strings: These are the sequence of characters.

Friday, July 3, 2020

CHAPTER-1 INTRODUCTION OF C PROGRAMMING LANGUAGE(PART2)

C program structure

A simple C program 


Program  Explanation

  • The first line “#include” is called as pre-processor directive. “stdio.h” is called a header file. 
  • This header file has declarations about standard input and output functions.
  • Next line is “int main()“. here  main() is the starting point of any c program. There is a return type specifies “int”, that informs the compiler that the function returns a value is of type int.
  • Next is opening brace ‘{‘, indicating the starting of function main().
  • Next line is a “printf()” function. This is used to display the output to the standard console. Note that every statement inside a function has ended with a semicolon. This informs the compiler that the statement has ended. And semicolon is mandatory to terminate a statement.
  •  Next is “return 0;“. This will return the program execution back to the called function. In this case compiler. In C, returning value 0 indicates the program completed without any issues.
  •  Last line is closing brace ‘}‘, indicating the end of function main().

 OUTPUT OF THE ABOVE PROGRAM IS:


C programming Rules

While writing any C program, we must follow below rules:

    • Every program should have a main() to run and generate an output.
    • All the statements should be terminated by a semicolon.
    • If the programmer has written only semicolon in a line, then it is treated as an empty statement.

    Ex:

    1. All the function names, variable names should be written in lower case, Upper case is used for symbolic constants.
    2. Every opening braces should have  closing braces.


    Important header files

    stdio.h : Provides input, output functions like printf(), scanf().

    conio.h : Console input and output, provides functions like clrscr(), getch().

    alloc.h : Provides memory allocation functions like malloc(), calloc(), free().

    math.h : Provides math related functions like abs(), squrt().

    string.h : Provides string related functions like strcpy(), strcat().

    assert.h : Provides macros like assert(int).


    C Comments

    Comments provide effective ways of knowing the functionality of a function. It is always a good practice to include comments in the beginning of a function with a short description of what it does.

    The part written inside comments will be ignored by the compiler and the comments will be stripped off while compiling the program.

    C supports 2 types of comments:

    •  Single line comment

           // This is a single line comment

    • Multiline comment

    /* This is

    an example of

    multiline comment

    */

    Example for comments:

    OUTPUT FOR THE ABOVE PROGRAM:

    Chapter-2(part-1)

    C Tokens: The smallest unit of a program and compiler identifies them as a token. Below are the types of Tokens available in C language. Key...