Presentation is loading. Please wait.

Presentation is loading. Please wait.

BASICS CONCEPTS OF ‘C’.  C Character Set C Character Set  Tokens in C Tokens in C  Constants Constants  Variables Variables  Global Variables Global.

Similar presentations


Presentation on theme: "BASICS CONCEPTS OF ‘C’.  C Character Set C Character Set  Tokens in C Tokens in C  Constants Constants  Variables Variables  Global Variables Global."— Presentation transcript:

1 BASICS CONCEPTS OF ‘C’

2  C Character Set C Character Set  Tokens in C Tokens in C  Constants Constants  Variables Variables  Global Variables Global Variables  Local Variables Local Variables

3  Like any other languages. C has own character set. A character denotes any letter or alphabet. digit or special symbol used to represent information LETTERS Upper Case A……………………….Z Lower Case a………………………..z DIGITS All decimal digits 0………………………..9 SPECIAL SYMBOLS + - * /. : “ ‘, ? { } [ ] ( ) & % ! @ # $ ^ BACK

4  Keywords ◦ C Contains 32 Keywords that have a standard,predefined meanings. These Keywords can be used only for their intended purposes. They can not be redefined by the programmers. These are reserved words of the C language. For example int, float, if, else, for, while, break, goto, for, continue, double, auto, void, union, short, return, extern, enum etc.  Identifiers ◦ An Identifier is a sequence of letters and digits, but must start with a letter. Underscore ( _ ) is treated as a letter. Identifiers are case sensitive. Identifiers are used to name variables, functions etc. ◦ Valid: Root, _getchar, __sin, x1, x2, x3, x_1, If ◦ Invalid: 324, short, price$, My Name

5  String Literals ◦ A sequence of characters enclosed in double quotes as “…”. For example “13” is a string literal and not number 13. ‘a’ and “a” are different.  Operators ◦ Arithmetic operators like +, -, *, /,% etc. ◦ Logical operators like ||, &&, ! etc. and so on.  White Spaces ◦ Spaces, new lines, tabs, comments ( A sequence of characters enclosed in /* and */ ) etc. These are used to separate the adjacent identifiers, kewords and constants.

6  Constants ◦ Constant is a quantity that remains unchanged during the execution of a program Constants like 13, ‘a’, 1.3e-5 etc. TYPES OF CONSTANTS  NUMERIC CONSTANTS 1. Integer Constant 2. Real Constant  CHARACTER CONSTANT 1. Single Character Constant 2. String Constant BACK

7  Integer Constants An Integer Constant is sequence of digits without decimal point. Rules for Constructing Integer Constant ◦ An integer Constant Must have at least one digit. ◦ Commas and Blank Spaces can not be included with in the no. ◦ It contains neither a decimal point nor an exponent. ◦ Sign(+ or -) must proceed the no. ◦ Default Sign is +ve. ◦ The allowable range for integer constant is -32768 to +32767 ◦ These are valid constants: 25-11+40 5678 etc. ◦ These are not valid constants: 25.07.1e 440 205- etc.

8  Real Constants An Real Constant is number that contains either a decimal point or an exponent Rules for Constructing Fractional Form Real Constant ◦ An Real Constant Must have at least one digit. ◦ Commas and Blank Spaces can not be included with in the no. ◦ It must contains decimal point. ◦ Sign(+ or -) must proceed the no. ◦ Default Sign is +ve. ◦ These are valid constants: 25.6-11.80.0345 567.889 etc. ◦ These are not valid constants: 25.07.1e 440 205- etc.

9 Rules for Constructing Exponential Form Real Constant ◦ The mantissa is either a real no expressed in decimal notation or an integer. ◦ Commas and Blank Spaces can not be included with in the no. ◦ It must contains decimal point. ◦ The exponent is always an integer no with an optional (+ or -) sign. ◦ Default Sign is +ve. ◦ The allowable range for real constant expressed in exponential form is -3.4e-38 to 3.4e38 ◦ These are valid constants: 0.5e3-1.8e-7 -1.4e+8 12e3 etc. ◦ These are not valid constants: 25.07.1e4.6 40 12 e 8 etc.

10  Character and string constants ◦ ‘c’, a single character in single quotes are stored as char. Some special character are represented as two characters in single quotes. ‘\n’ = newline, ‘\t’= tab, ‘\\’ = backlash, ‘\”’ = double quotes. Char constants also can be written in terms of their ASCII code. ‘\060’ = ‘0’ (Decimal code is 48). ◦ A sequence of characters enclosed in double quotes is called a string constant or string literal. For example “Charu” “A” “3/9” “x = 5” BACK

11 A Variable is a data name that may be used to store a data value. A variable may take different values at different times during the execution of a program. Variable must defined before they are used in a program.  Naming a Variable ◦ A variable may consist of letters, digits and undersore. ◦ Must not be a keyword ◦ Variables are identified by only first 32 characters. ◦ Special symbols and blanks are not allowed. ◦ Both Uppercase and Lowercase letters are allowed and are conidered to be distinguishable. ◦ Not valid Variables are: ram Kumar char 8 th price$ etc ◦ Valid Variables are: area sum avg total etc

12  Declaring a Variable ◦ Each variable used must be declared. ◦ A form of a declaration statement is data-type var1, var2,…; ◦ Declaration announces the data type of a variable and allocates appropriate memory location. No initial value (like 0 for integers) should be assumed. ◦ It is possible to assign an initial value to a variable in the declaration itself. data-type var = expression; ◦ Examples int sum = 0;

13  Global Variables ◦ These variables are declared outside all functions. ◦ Life time of a global variable is the entire execution period of the program. ◦ Can be accessed by any function defined below the declaration, in a file. /* Compute Area and Perimeter of a circle */ #include float pi = 3.14159; /* Global */ main() { floatrad;/* Local */ printf( “Enter the radius “ ); scanf(“%f”, &rad); if ( rad > 0.0 ) { float area = pi * rad * rad; float peri = 2 * pi * rad; printf( “Area = %f\n”, area ); printf( “Peri = %f\n”, peri ); } else printf( “Negative radius\n”); printf( “Area = %f\n”, area ); } /* Compute Area and Perimeter of a circle */ #include float pi = 3.14159; /* Global */ main() { floatrad;/* Local */ printf( “Enter the radius “ ); scanf(“%f”, &rad); if ( rad > 0.0 ) { float area = pi * rad * rad; float peri = 2 * pi * rad; printf( “Area = %f\n”, area ); printf( “Peri = %f\n”, peri ); } else printf( “Negative radius\n”); printf( “Area = %f\n”, area ); } BACK

14  Local Variables ◦ These variables are declared inside some functions. ◦ Life time of a local variable is the entire execution period of the function in which it is defined. ◦ Cannot be accessed by any other function. ◦ In general variables declared inside a block are accessible only in that block. /* Compute Area and Perimeter of a circle */ #include float pi = 3.14159; /* Global */ main() { floatrad;/* Local */ printf( “Enter the radius “ ); scanf(“%f”, &rad); if ( rad > 0.0 ) { float area = pi * rad * rad; float peri = 2 * pi * rad; printf( “Area = %f\n”, area ); printf( “Peri = %f\n”, peri ); } else printf( “Negative radius\n”); printf( “Area = %f\n”, area ); } /* Compute Area and Perimeter of a circle */ #include float pi = 3.14159; /* Global */ main() { floatrad;/* Local */ printf( “Enter the radius “ ); scanf(“%f”, &rad); if ( rad > 0.0 ) { float area = pi * rad * rad; float peri = 2 * pi * rad; printf( “Area = %f\n”, area ); printf( “Peri = %f\n”, peri ); } else printf( “Negative radius\n”); printf( “Area = %f\n”, area ); } BACK

15


Download ppt "BASICS CONCEPTS OF ‘C’.  C Character Set C Character Set  Tokens in C Tokens in C  Constants Constants  Variables Variables  Global Variables Global."

Similar presentations


Ads by Google