Presentation is loading. Please wait.

Presentation is loading. Please wait.

Fundamentals of Computer and programming in C Programming in C Rohit Khokher.

Similar presentations


Presentation on theme: "Fundamentals of Computer and programming in C Programming in C Rohit Khokher."— Presentation transcript:

1 Fundamentals of Computer and programming in C Programming in C Rohit Khokher

2 Programming in C History of C Importance of C Structure of C Programs Character Set, tokens, key words & identifiers. Data Types Constants – Symbolic class Variables Declarations – Variables A variable as a constant A variable as volatile – Storage class Data overflow & underflow Already covered Self study

3 Character Set, tokens, key words & identifiers. Character Set – Letters (Uppercase A-Z, Lowercase a-z) – Digits 0-9 – Special characters Comma Period Semicolon Colon Question mark Apostrophe Quotation mark Exclamation mark Vertical bar Slash Backlash Tilde Under score Dollar,. ; : ? ! | / \ ~ _ $ Percent sign Caret Asterisks Minus sign Plus sign Less than Greater than Left parenthesis Right parenthesis Left brace Right brace Number sign Left bracket Right bracket %^*-+<>(){}#[]%^*-+<>(){}#[] Equal WHITE SPACES Blank space Horizontal tab Carriage Return New line Form feed =

4 Tokens Keywords ConstantsStrings Operators IdentifiersSpecial symbols Words with fixed meaning. Must be written in lower case. Example: main, int, float … Variable names symbolizing memory addresses. Rules for creating identifiers 1.The first character must be an alphabet or underscore. 2.Must consists of letters, digits, or underscore 3.May have 256 characters but only the first 31 characters are important 4.Should be a keyword 5.Should contain white spaces Numeric constants like -59.67 Character constants like Year 2010 Year 2010 [. ]. {. }. (. … +, -, *, /, …

5 Tokens key words or reserve words (Prepare a list of ANSI C Key words) Constants NumericCharacter IntegerReal Single String Decimal, Octal and Hexadecimal Backslash \a bell sound \f backspace \n new line \t horizontal tab …..

6 Example #include void main { printf (Integer values \n\n); printf (%d %d %d \n, 32767, 32767+1, 3267+10); printf (\n); } Integer Values 3276 -32768 -32759 Output Why negative?

7 Data Types Primary Data Types integer floating Point signedunsigned Character Int short int long int Int short int long int unsigned int unsigned short int unsigned long int unsigned int unsigned short int unsigned long int float Double Long double float Double Long double Signed -128 to 127 Signed -128 to 127 Unsigned 0 to 255 Unsigned 0 to 255 Exercise: Find the size and range of each data type void

8 Variable Declaration Data TypeKeywordDeclaration in C Character (8 bits)charchar a, b, c; Unsigned Characterunsigned charunsigned char a, b, c; Signed Charactersigned charsigned char a, b, c; Integer (16 bits)intint x, y, z; Short Integer (8 bits)short intshort int x, y, z; Long Integer (32 bits)long intlong int x, y, z; Real (32 bits)floatFloat x,y,z; Real (64 bits)doubledouble x, y, z; Real (89 bits)long doubleLong double x, y, z;

9 Example # include float x, y; int code; short intcount; long intamount; doubledeviation; unsigned n; char c; /*--------------------*/ Main () { } x: 4 Bytes y;4 Bytes code;2 Byte count;1 Bytes amount;4 Bytes deviation;8 Bytes n;2 Bytes c;1 Byte x: 4 Bytes y;4 Bytes code;2 Byte count;1 Bytes amount;4 Bytes deviation;8 Bytes n;2 Bytes c;1 Byte Data Segment

10 User defined Data types typedef User can define type using typedef feature. Example typedefintunit; typedef floatmarks; Unit symbolizes int and marks float. unit x, y, z; means x, y and z are integer type. float a, b, c; means a, b, and c are float type.

11 User defined data type enum (enumerated type) – enum identifier ( value 1, value 2, …, value n ) Example Definition enum day (Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday); Variable Declaration enum day week_st, week_end; These declaration day week_st and week_end can take values in (Monday to Sunday) and we can use them as week_st = Monday; week_end=Friday;

12 Storage Class Location and visibility of variables. # include float x, y; void main () { int i; floatb; -- - - functionx (); } float functionx (); { int i; float s; } y bi si x Global x, y are visible to Main and functionx Global x, y are visible to Main and functionx Local to main The variables i and b are visible to main only Local functionx The variables i and s are visible to functionx only Data segment

13 Storage class and their meaning auto : known within the function it is declared. static: a local variable that retains its velue even after the control is transferred to calling program. extern: global variable known to all functions. register: a local variable that is stored in a register.

14 Assigning values to variables Assignment statement – Assignment statement is defined as identifier = expression where expression give a value. Example fee = 20.5; rent = 56; expense = fee + rent;

15 Programing example # include void main() { float x, p; double y, q; unsigned k; int m=54321; long intn=1234567890; x = 1.2345678900; y= 9.87654321; k= 54321; P=q=1.0; printf ( m = %d \n, m); printf ( n = %ld \n, n); printf ( x = %.121f \n, x); printf ( x = %f \n, x); printf ( y = %.121f \n, y); printf ( y = %f \n, y); printf ( k = %u p = %f q = %.121f \n, k,p,q); }

16 Defining Synbolic Constants #define directives – #define PI 3.14 – #define PASS_MARK 50 – #define MAX = 100 – #define STRENGTH 200


Download ppt "Fundamentals of Computer and programming in C Programming in C Rohit Khokher."

Similar presentations


Ads by Google