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:

    Friday, June 26, 2020

    CHAPTER-1 INTRODUCTION OF C PROGRAMMING LANGUAGE(PART1)

    First of all we should know what is language ?
     
    Ans : A language is a system of communication which consists of a set of sounds and written symbols which are used by the people of a particular country or region for talking or writing. While talking to computer language i.e. programming language ,"It is a formal language that comprises a set of instructions for producing different kinds of output accordingly. "

    Introduction to C Language 
    • C is a Procedural programming language. This means there will a series of statements inside a procedure (function) that needs to be carried out.
    • C is a programming language that is developed at AT & T's Bell Laboratories of USAin  1972 and it is designed and written by Dennis Ritchie.
    • C11 is the latest stable version released in 2011 December. This is supported by all major C compilers.
    • C is a middle level programming language.
    • Many other programming languages like Java, Go, C# have been heavily influenced by C.
    • C programming allows static and dynamic memory management.
    • During 1970 and 1980 many versions of C have been implemented. Hence in 1989 ANSI C was introduced and was later accepted by ISO in 1990.
    • All the C source file will be saved as .c file extension. Example “hello.c”
    • All the C header file will be saved as .h file extension. Example “stdio.h”
    • C started to replace languages of that time like PL/I , ALGOL, FORTRAN etc.
      

    Features of C language:

    • Robust
    • Portable
    • Fast
    • Simple and easy to learn
    • Extensible

    Why to learn C language 

    There are several reasons for this. These are as follows :
    1.  Major parts of popular OS(Operating Systems) like Windows, Unix, Linux are still written in C.
    2. Embedded systems use C language. Like processors of Smart Phones, Digital cameras , Washing machines etc.
    3.  To interact with the hardware devices C is used.
    4. Different 3D computer games are still written in C (not all the codes but majority).


    Disadvantages of C language:

    • Not an object-oriented language.
    • Some code needs to be recompiled when running on a different machine.
    • No constructors and destructors .
    • There is no runtime checking. An error is known only after execution of a c program.
    • There is no strict type checking. In C programming language we can send integer value for a float data type.
    • No data security is available.
    NOTE: C is able to access low-level memory of hardware. This helps a programmer to develop efficient code. Hence C language is called as a middle-level programming language.







    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...