1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

For Beginners In C

Discussion in 'C' started by pankaj.sea, Feb 16, 2010.

  1. pankaj.sea

    pankaj.sea New Member

    Joined:
    Apr 6, 2009
    Messages:
    461
    Likes Received:
    13
    Trophy Points:
    0
    Occupation:
    Web Developer
    Location:
    Kolkata
    Home Page:
    Hello All Visitors and Members!
    Here, I'm going to start a small "Short Note" series for beginners! Means, here I'm going to describe all C items step by step! Such as why should we use
    or what is the purpose of
    :)
     
  2. pankaj.sea

    pankaj.sea New Member

    Joined:
    Apr 6, 2009
    Messages:
    461
    Likes Received:
    13
    Trophy Points:
    0
    Occupation:
    Web Developer
    Location:
    Kolkata
    Home Page:
    #include<xxx.h>

    What Is #?
    # denotes preprocessor, in simple word, it gives instruction to the compiler to compile those lines first who are started with #.

    What is a .h file?
    A .h file is called header file. It contains some definitions or codes of some functions which are usually used in every program. Such as, if you do not give the line
    then your compiler will give error if you have used
    So, #include<xxx.h> is used to include some codes to your programs, which are predefined!

    Information:
    Basically used to use scanf or printf.
    Basically used for getch();
    Basically used for some mathematical functions, e.g, sqrt etc.
     
  3. techinspiration

    techinspiration New Member

    Joined:
    Feb 14, 2010
    Messages:
    54
    Likes Received:
    0
    Trophy Points:
    0
    Nice topic started!
    ;)
     
  4. pankaj.sea

    pankaj.sea New Member

    Joined:
    Apr 6, 2009
    Messages:
    461
    Likes Received:
    13
    Trophy Points:
    0
    Occupation:
    Web Developer
    Location:
    Kolkata
    Home Page:
    Thank U techinspiration!
    ;)
     
  5. pankaj.sea

    pankaj.sea New Member

    Joined:
    Apr 6, 2009
    Messages:
    461
    Likes Received:
    13
    Trophy Points:
    0
    Occupation:
    Web Developer
    Location:
    Kolkata
    Home Page:
    printf(); and scanf();
    printf is usually used to display something in the terminal or screen!
    syntax-
    Code:
    printf("Target Word");
    and
    printf("%d",xxx);
    the second term is used to display any integer or float or whatever!
    [hr]
    scanf is usually used to take inputs from user!
    syntax-
    Code:
    scanf("%d",&xxx);
    the %d can be replaced by %f for floating point values, %c for characters etc.
     
  6. pankaj.sea

    pankaj.sea New Member

    Joined:
    Apr 6, 2009
    Messages:
    461
    Likes Received:
    13
    Trophy Points:
    0
    Occupation:
    Web Developer
    Location:
    Kolkata
    Home Page:
    getch();
    this is used in old C compilers, this is used to hold the results on the terminal widow! If you forget to give it, then after compiling and calculating the whole result, the terminal will go off without showing the result.
    syntax:
    Code:
    getch();
    should be used before the closing bracket of
    Code:
    void main()
    {
    ........
    ........
    getch();
    }
     
  7. pankaj.sea

    pankaj.sea New Member

    Joined:
    Apr 6, 2009
    Messages:
    461
    Likes Received:
    13
    Trophy Points:
    0
    Occupation:
    Web Developer
    Location:
    Kolkata
    Home Page:
    if - else
    if - else condition is generally used for a single condition checking statements. Such as if x=2 then you have to add 1 with y else add 2 with y etc.
    So how to write the statement?
    Code:
    if(x=2)
    {
    z=y+1;
    printf("%d",z);
    }
    else
    {
    z=y+2;
    printf("%d",z);
    }
    in addition to this, when you have single statement in if or in else section then its not necessary to give the brackets {}.
     
  8. techinspiration

    techinspiration New Member

    Joined:
    Feb 14, 2010
    Messages:
    54
    Likes Received:
    0
    Trophy Points:
    0
    I would like to add SWITCH - CASE to this:
    What is it?
    This is used to declare many conditions, such as
    etc.

    syntax
    Code:
    switch(x)
    default:
    [i]statement[/i]
    break;
    case 1:
    [i]statement[/i]
    break;
    
    case 2:
    [i]statement[/i]
    break;
    
    case 3:
    [i]statement[/i]
    break;
     
  9. pankaj.sea

    pankaj.sea New Member

    Joined:
    Apr 6, 2009
    Messages:
    461
    Likes Received:
    13
    Trophy Points:
    0
    Occupation:
    Web Developer
    Location:
    Kolkata
    Home Page:
    hi techinspiration!
    what you have posted is right but needs to be cleared with an example-
    Here is ti:
    Code:
    ...
    int choice;
    ...
    scanf("%d",&choice);
    switch(choice)
    default:
    printf("Wrong Entry!!!"):
    case 1:
    if(x>10)
      y=x+2;
    else
      y=x+5;
    printf("%d",y);
    break;
    
    case 2:
    if(x<10)
      y=x+10;
    printf("%d",y);
    break;
    Hope this will help more to understand the SWITCH - CASE
     
  10. pankaj.sea

    pankaj.sea New Member

    Joined:
    Apr 6, 2009
    Messages:
    461
    Likes Received:
    13
    Trophy Points:
    0
    Occupation:
    Web Developer
    Location:
    Kolkata
    Home Page:
    do - while
    This is usually used to do some operation first and then to check a condition, such as
    Code:
    do
    {
    scanf("%d",&x);
    y=x+2;
    }
    while(y>3)
    
    means compiler will execute the code again if the ans i.e, y is greater than 3.

    Syntax:
    Code:
    do
    {
    statement;
    }
    while(argument)
     
  11. pankaj.sea

    pankaj.sea New Member

    Joined:
    Apr 6, 2009
    Messages:
    461
    Likes Received:
    13
    Trophy Points:
    0
    Occupation:
    Web Developer
    Location:
    Kolkata
    Home Page:
    WHILE loop
    syntax:
    Code:
    while(condition)
    {
    statement
    }
    
    This loop is also called Entry Controlled loop. This is usually used to make such sections where a particular is to be compared with another.
    Suppose, you given that
    input a value x, then add 1 with y (another integer) until x reaches to 10. for this type of arguments we can use while loop.
    Example:
    Code:
    while(x<11)
    {
    y=y+1;
    x++;
    }
    This is the solution of the above problem!
     

Share This Page