Programming in C - 03 - Basic Syntax

download Programming in C - 03 - Basic Syntax

of 31

Transcript of Programming in C - 03 - Basic Syntax

  • 8/17/2019 Programming in C - 03 - Basic Syntax

    1/31

    Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net 

    Programming Basi

    http://www.wibit.net/http://www.wibit.net/

  • 8/17/2019 Programming in C - 03 - Basic Syntax

    2/31

    Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net 

    Overview

    Semicolon

    Variable Declarations Code Blocks

    Functions

    Comments

    http://www.wibit.net/http://www.wibit.net/

  • 8/17/2019 Programming in C - 03 - Basic Syntax

    3/31

    Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net 

    Semicolon ;

    Terminator

    • Signifies the end of a statement• Many statements end with a ‘;’ and some do n

    • Can also be used to “stack” statements 

    http://www.wibit.net/http://www.wibit.net/

  • 8/17/2019 Programming in C - 03 - Basic Syntax

    4/31

    Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net 

    Variable Declaration

    How to declare a variable in C

        = ;

    http://www.wibit.net/http://www.wibit.net/

  • 8/17/2019 Programming in C - 03 - Basic Syntax

    5/31Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net 

    Variable Declaration

    How to declare a variable in C

    int num = 10;

    http://www.wibit.net/http://www.wibit.net/

  • 8/17/2019 Programming in C - 03 - Basic Syntax

    6/31Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net 

    Variable Declaration

    How to declare a variable in C

    int num = 10;

    Variable Type

    http://www.wibit.net/http://www.wibit.net/

  • 8/17/2019 Programming in C - 03 - Basic Syntax

    7/31Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net 

    Variable Declaration

    How to declare a variable in C

    int num = 10;

    Variable Name

    http://www.wibit.net/http://www.wibit.net/

  • 8/17/2019 Programming in C - 03 - Basic Syntax

    8/31Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net 

    Variable Declaration

    How to declare a variable in C

    int num = 10;

    Expression (Value)

    http://www.wibit.net/http://www.wibit.net/

  • 8/17/2019 Programming in C - 03 - Basic Syntax

    9/31Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net 

    Variable Declaration

    How to declare a variable in C

    int num = 10;

    Terminator

    http://www.wibit.net/http://www.wibit.net/

  • 8/17/2019 Programming in C - 03 - Basic Syntax

    10/31Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net 

    Variable Declaration

    How to declare a variable in C

    int num;

    num = 10;

    http://www.wibit.net/http://www.wibit.net/

  • 8/17/2019 Programming in C - 03 - Basic Syntax

    11/31Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net 

    Variable Declaration

    How to declare a variable in C

    int num;

    num = 10; Variable declaration

    Set variable value

    http://www.wibit.net/http://www.wibit.net/

  • 8/17/2019 Programming in C - 03 - Basic Syntax

    12/31

    Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net 

    Terminator

    Variable Declaration

    How to stack variable declarations

    int x = 10;int y = 1 + 2;

    http://www.wibit.net/http://www.wibit.net/

  • 8/17/2019 Programming in C - 03 - Basic Syntax

    13/31

    Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net 

    Variable Declaration

    How to stack variable declarations

    int x = 10;int y = 1 + 2;

    Same as

    int x = 10, y = 1 + 2;

    V i bl D l i

    http://www.wibit.net/http://www.wibit.net/

  • 8/17/2019 Programming in C - 03 - Basic Syntax

    14/31

    Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net 

    Variable Declaration

    Whitespace is ignored by the compiler

    int y = 1 + 2;

    int y=1+2;

    Same ex

    C d Bl k

    http://www.wibit.net/http://www.wibit.net/

  • 8/17/2019 Programming in C - 03 - Basic Syntax

    15/31

    Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net 

    Code Blocks

    Sections code that belongs to a particular str

    {

     

    Start Code Block

    End Code Block

    C d Bl k

    http://www.wibit.net/http://www.wibit.net/

  • 8/17/2019 Programming in C - 03 - Basic Syntax

    16/31

    Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net 

    Code Blocks

    Sections code that belongs to a particular structure

    int main(){

    if (x == y)

    {

    }

    return 0;

    }

    Start MainBlock

    End MainBloc

    Start If Co

    End If C

    F ti D l ti

    http://www.wibit.net/http://www.wibit.net/

  • 8/17/2019 Programming in C - 03 - Basic Syntax

    17/31

    Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net 

    Function Declaration

    How to declare a function

        (

  • 8/17/2019 Programming in C - 03 - Basic Syntax

    18/31

    Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net 

    Function Declaration

    How to declare a function

        (

  • 8/17/2019 Programming in C - 03 - Basic Syntax

    19/31

    Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net 

    Function Declaration

    How to declare a function

        (

  • 8/17/2019 Programming in C - 03 - Basic Syntax

    20/31

    Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net 

    Function Declaration

    How to declare a function

        (

  • 8/17/2019 Programming in C - 03 - Basic Syntax

    21/31

    Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net 

    Function Declaration

    How to declare a function

        (

  • 8/17/2019 Programming in C - 03 - Basic Syntax

    22/31

    Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net 

    Function Declaration

    Variable Type

    How to declare a function

        (

  • 8/17/2019 Programming in C - 03 - Basic Syntax

    23/31

    Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net 

    Function Declaration

    Local VariableName

    How to declare a function

        (

  • 8/17/2019 Programming in C - 03 - Basic Syntax

    24/31

    Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net 

    Function Declaration

    ParameSeparato

    How to declare a function

        (

  • 8/17/2019 Programming in C - 03 - Basic Syntax

    25/31

    Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net 

    Function Declaration

    Next parame

    How to declare a function

        (

  • 8/17/2019 Programming in C - 03 - Basic Syntax

    26/31

    Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net 

    Calling a Function

    ();

    Power(2, 3);

    or

    int x = Power(2, 3);

    Calling a Function

    http://www.wibit.net/http://www.wibit.net/

  • 8/17/2019 Programming in C - 03 - Basic Syntax

    27/31

    Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net 

    Calling a Function

    ();

    Power(2, 3);

    or

    int x = Power(2, 3);

    http://www.wibit.net/http://www.wibit.net/

  • 8/17/2019 Programming in C - 03 - Basic Syntax

    28/31

    Writing a Comment

  • 8/17/2019 Programming in C - 03 - Basic Syntax

    29/31

    Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net 

    Writing a Comment

    int x = Power(2, 3);

    //Comment a single line with two sl

    //Print the statement below

     printf(“The result is %d\n“, x); 

    //Reset the variable ‘x’ to 0. 

    x = 0;

    Writing a Comment

    http://www.wibit.net/http://www.wibit.net/

  • 8/17/2019 Programming in C - 03 - Basic Syntax

    30/31

    Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net 

    Writing a Comment

    int x = Power(2, 3);

    /*

    Block comments can span multiple l

    Next we will print the statement b

    */

     printf(“The result is %d\n“, x); 

    x = 0; //Reset the variable ‘x’ to

    http://www.wibit.net/http://www.wibit.net/

  • 8/17/2019 Programming in C - 03 - Basic Syntax

    31/31

    Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net 

    Programming

    Thanks for

    http://www.wibit.net/http://www.wibit.net/