1 / 13

C Fundamentals

Primitive Types. Integer typeschar : 8 bitshort : 16 bitint : 32 bitlong : 64 bitReal Typesfloat - 32 bit real numbersdouble - 64 bit real numbers. Constants. In Java constants are variables that are never allowed to change valuepublic static final int abc = 100;In C constants are defined

Leo
Download Presentation

C Fundamentals

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


    1. C++ Fundamentals CS-240 Dick Steflik

    2. Primitive Types Integer types char : 8 bit short : 16 bit int : 32 bit long : 64 bit Real Types float - 32 bit real numbers double - 64 bit real numbers

    3. Constants In Java constants are variables that are never allowed to change value public static final int abc = 100; In C++ constants are defined as: const int abc = 100 ; const char plus = ‘+’; constants are resolved by the compiler preprocessor by doing text substitutions of the value for all occurrences of the name.

    4. Boolean (false/true) C++ has no boolean type like Java the value 0 represents false any other value represents true the statement “if (50) cout <<“t”; will always print “t” as 50 is not 0 so the predicate is true the statement “if (5-5) cout<<“t”; else cout << “f” ; will always print “f” as (5-5) is 0 (i.e. False)

    5. Strings C++ has no built-in String type like Java Strings are implemented as null terminated arrays of characters. char [3] abc = “me” array abc consists of “m”, “e”, null abc = “me” (shortcut for defining and initializing a string) string functions are in <string.h>

    6. Derived Types These operators create new types from the basic types * pointer to *const constant pointer & reference to (addressing operator) [] vector of () function returning

    7. Null statements the simplest statement is the null statement ; useful if the syntax requires a statement for instance to introduce a time delay into a program: for (int j = 0 ; j < 100 ; j++) {;}

    8. C++ Program Structure A C++ Program consists a set of file(s) consisting of declarations of: types functions variables constants

    9. externalization To use a name to refer to the same thing in two different source files it must be defined as external extern double sqrt(double) ; extern istream cin ; extern int abcd ;

    10. Header files To guarantee consistency between source files externalize definitions into header (.h) files for instance math.h contains the externalized definitions for interfacing to the mathematic system utilities. To use the functions in math.h include math.h in your source file #include <math.h>

    11. Header files (cont.) math.h is provided as part of C++ but you can make your own header files to include your own header file, place it in the same directory as the files to use it and in each source file place the line #include “myfile.h” note the “” instead if < >, use < > to include from the standard “include” directory use “” to include from elsewhere (full path)

    12. Example

More Related