Header Ads

C Programming

Introduction : 

C programming is a general-purpose, procedural, imperative computer programming language developed in 1972 by Dennis M Ritchie of Bell Telephone Laboratories for the development of the UNIX operating system.

Features of C Language :

  • Simple
  • Machine independent or portable 
  • Mid - level programming language 
  • Structured programming language 
  • Rich Library
  • Memory Management
  • Fast Speed
  • Pointers
  • Recursion
  • Extensible

Advantages of C :

  • Easy to Learn
  • Structured Language 
  • It produces efficient programs
  • It can handle low level activities
  • It can be compiled on a variety of computer platforms

First C Program : 

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

Comments in C :

Comments are used to tell a person something about the code. Comments are treated as empty by the compiler and do not change the actual meaning of the code.

There are two types of comments : 

  1. Single Line Comment
  2. Multi - Line Comment
#include<stdio.h>
int main(){
    //this is a single line comment
    printf("Hello Step Towards Coding");

    /* this is multi
 line comment */
    return 0;
}

Variables in C :

A variable is a name of the memory location. It is used to store data. Its Value can be changed and it can be reused many times.
Example : int a 
                  float b
                  char c


Data type  in C :

The data type determines the type of data that the variable can store, such as integer, float, character, etc.

There are two types of data types in C : 

  1. Primitive 
  • int
  • float
  • char
  • double
  •       
          2. Non-Primitive
    • array
    • structure
    • enum
    • union
    • pointer


    Control Statement :

    There are the following varient of if statement in C language
    • If statement
    • If - else statement
    • If else - If ladder 
    • Nested if

    If Statement

    The if statement is used to check a certain given condition and perform some operation depending on whether the condition is true.

    // if syntax
    if(condition){
    //code
    }

    If - else Statement

    The if-else statement is used to perform operations based on some specific condition. The operation determines whether the block is executed if and only if the given condition is true.

    if(expression){
    //if block
    } else{
    //else block
    }

    If else - if ladder

    A common programming construct that is based on nested if is the if - else - if ladder. Conditional expressions are evaluated from top to bottom. Once a true condition is found, the associated statement is executed and the rest is skipped

    if(condition 1){
    // condition 1 is true
    } else if(condition 2){
    //condition 2 is true
    } else if(condition 3){
    // condition 3 is true
    }
    .
    .
    .
    else{
    //case to be executed if all the conditions are false
    }

    Nested if

    Nested if in C programming is placing if statement inside another if statement. Nested if in C is helpful if you want to check the condition inside a condition. If else statement prints statements based on the expression result(True, False). Sometimes we have to check even further when the condition is TRUE.

    if(expression){
        if(expression){
            //code
        }else{
            //code
        }
    }
    else{
    //code
    }





    Related Links :

    Post a Comment

    0 Comments