This is a official website of instagram page @coding_planet

Friday, February 22, 2019

C Introduction (Post 1)

               C Language Introduction


C is a procedural programming language. It was initially developed by Dennis Ritchie between 1969 and 1973. It was mainly developed as a system programming language to write operating system. The main features of C language include low-level access to memory, simple set of keywords, and clean style, these features make C language suitable for system programming like operating system or compiler development.
Many later languages have borrowed syntax/features directly or indirectly from C language. Like syntax of Java, PHP, JavaScript and many other languages is mainly based on C language. C++ is nearly a superset of C language (There are few programs that may compile in C, but not in C++).


Beginning with C programming:
  1. Structure of a C program
    After the above discussion, we can formally assess the structure of a C program. By structure, it is meant that any program can be written in this structure only.


Structure Of C Program

Header                                               #include<stdio.h>


Main                                                   int  main() {


Variable Declaration                          int a=10;


Body                                                  printf("itechbizz");


Return                                               return 0; }




Components Of Above Structure

1. Header File Inclusion: The First Component we have to include while writing C Program.
    A Header File Is a file with extension .h which contains C function declarations and some      macro definitions to be shared between source files.




   Some Of C Header Files;


        stddef.h – Defines several useful types and macros.stdint.h – Defines exact width                   integer types.
        stdio.h – Defines core input and output functions
        stdlib.h – Defines numeric conversion functions, pseudo-random network generator,              memory allocation
        string.h – Defines string handling functions

        math.h – Defines common mathematical functions

Syntax(Structure) to include a header file in C:

#include <(header_filename).h>

Main Method Declaration: The next Step of a C program is to declare the main() function. The syntax to declare the main function is:
Syntax(Structure) to include a header file in C:

int main()
{}


Variable Declaration: The step  of any C program is the variable declaration. It refers to the variables that are to be used in the function. 
Example:

int main()
{
    int a;
.
.


Body: Body of a function in C program, refers to the operations that are performed in the functions. It can be anything like manipulations, searching, sorting, printing, etc..
Example:

int main()
{
    int a;
    scanf("");
    printf("%d", a);
.


Return Statement: The last part in any C program is the return statement. The return statement refers to the returning of the values from a function. This return statement and return value depend upon the return-type of the function. For example, 

For void Type function there is no need of return value.
For int Type function we have to give a return type means return value..

for better illustration see example

Example:

int main()
{
    int a;
    scanf("");
    printf("%d", a);
    
    return 0;
}

Writing first program:
Following is first program in C

#include <stdio.h>
int main(void)
{
    printf("itechbizz");
    return 0;
}
  1.  [ #include <stdio.h> ] In a C program, all lines that start with are processed by preprocessor which is a program invoked by the compiler.  In the above example, preprocessor copies the preprocessed code of stdio.h to our file. The .h files are called header files in C. These header files generally contain declaration of functions. We need stdio.h for the function printf() used in the program.


    [ int main(void) ]  The void written in brackets indicates that the main doesn’t take any parameter  main() can be written to take parameters also. We will be covering that in future posts.
     [ { and } ] In C language, a pair of curly brackets(parenthesis brackets) define a scope and mainly used in functions and control statements like if, else, loops. All functions must start and end with curly brackets.
     [ printf(“itechbizz”); ] printf() is a standard library function to print something on standard output. The semicolon at the end of printf indicates line termination. In C, semicolon is always used to indicate end of statement.
     [ return 0; ] The return statement returns the value from main(). The returned value may be used by operating system to know termination status of your program. The value 0 typically means successful termination.
  2. How to excecute the above program:
    Online Compilershttps://ide.geeksforgeeks.org/http://ideone.com/ or http://codepad.org/ 
  3. Windows: There are many compilers available freely for compilation of C programs like Code Blocks  and Dev-CPP.   
  4. Linux: For Linux, gcc comes bundled with the linux,  

Code Blocks Is Also Available For Linux







Share:

Related Posts:

0 Comments:

Post a Comment

About

Blogger templates

3/recent/post-list