basic features of c

Upload: hasanur-rahman-mishu

Post on 14-Apr-2018

218 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/30/2019 Basic Features of c

    1/16

    BASIC FEATURES OF C++

  • 7/30/2019 Basic Features of c

    2/16

    Characters and character set

    The characters used in the C++ program are

    upper and lower case letters, A to Z and a to z

    digits 0 to 9

    the space character

    control characters- new line, horizontal andvertical tab, form feed, bell

    special characters (or symbols)

    _ { } [ ] # ( ) < > $ : ; . ? * + -/ ^ & | ~ ! = , \ " '

  • 7/30/2019 Basic Features of c

    3/16

    Variable

    A variable is a name given to a memorylocation where you can store a data of a

    particular type. The type is specified when thevariable is declared.

    The name you can give to a variable canconsist of any combination of upper or lowercase letters, underscores ( _ ) and the digits (

    0 to 9 ).

  • 7/30/2019 Basic Features of c

    4/16

    A variable name is case sensitive. (C++ is acase sensitive language). This means length

    and Length, LENGTH are different names.

    A variable name cannot begin with a digit.

    Examples of variable names:

    monthly_salary, temperature, pay, mark,mark_ce204,

  • 7/30/2019 Basic Features of c

    5/16

    Declaration of Variable

    Examples of variable declaration:

    int student_no;

    int age;

    int student_no, age;

    string name;

    double length, width, area;

    int count=0;

    int a=5, b=2;

  • 7/30/2019 Basic Features of c

    6/16

    Basic data types

    char

    short

    int

    long

    float

    double

    long double

    string

  • 7/30/2019 Basic Features of c

    7/16

    There are also type such as unsignedlong, unsigned short, unsigned intsigned long, signed short, signed int.

    Typically float will provide 7 digitprecision, double will provide 15 digit

    precision and long double will provide19 digit precision

  • 7/30/2019 Basic Features of c

    8/16

    Keywords

    These are reserved words that have particularsignificance and when needed are to be used

    as it is. In the above program include,iostream, using, namespace, std, int, cout,return are keywords.

  • 7/30/2019 Basic Features of c

    9/16

    blocks

    A statement is analogous to a sentencein any language.

    A C++ statement expresses a completeinstruction to the computer. Statementsare basic units for specifying what our

    program is to do.

    Most C++ statements end with a

    semicolon.

  • 7/30/2019 Basic Features of c

    10/16

    Examples of C++ statement andstatement block:

    #include

    double result; //declaration

    double result=0.0; //declaration and initialization

    length = 5.0; // assignment

    if(marks>=40)

    cout

  • 7/30/2019 Basic Features of c

    11/16

    Whitespace

    Whitespace refers to spaces, horizontal andvertical tabs and newline characters.Whitespaces are required in a C++ statement forthe compiler to be able to distinguish between the

    elements of the statement.

  • 7/30/2019 Basic Features of c

    12/16

    Function, function name and

    function body

    A function is a self-contained block of codereferenced by a name. There may be morethan one function in a C++ program, but there

    shall be at least one function named mainandnot more than one function shall have thename main.

    The brackets ( ) after the function name isessential. A function may have arguments thatare placed within these brackets.

    The function has a type.

  • 7/30/2019 Basic Features of c

    13/16

    directive

    #include includes the contents of theheader file iostream into the program.

    iostream is one of several standard header files thatare supplied with C++ compiler.

    The header files contain information (code) for theavailable library functions. The name cout is defined inthe header file iostream. This is a standard header filethat provides the definitions necessary for standardinput and output facilities. The standard input device isthe keyboard and the standard output device is themonitor.

  • 7/30/2019 Basic Features of c

    14/16

    Namespace

    The namespace refers to a group of severalnames (or entities). The entities in the C++standard library are all defined within anamespace called std. You may also consider

    namespace as a surname. You may consider thatthe full name ofcout is std::cout. If we omit theusing directive we can write the output statementas

    std::cout

  • 7/30/2019 Basic Features of c

    15/16

    Returnstatement The return statement ends the function and

    returns control to the operating system. It alsoreturns a value (0 in the above example) to theoperating system.

  • 7/30/2019 Basic Features of c

    16/16

    EXAMPLE

    /* Program that finds the average

    of two numbers */

    #include

    using namespace std;

    int main()

    {

    double num1, num2, average;

    cout