Presentation is loading. Please wait.

Presentation is loading. Please wait.

C AS A LANGUAGE Interface between computer & human being. ALPHABETS

Similar presentations


Presentation on theme: "C AS A LANGUAGE Interface between computer & human being. ALPHABETS"— Presentation transcript:

1 C AS A LANGUAGE Interface between computer & human being. ALPHABETS
WORDS SENTENCES PARAGRAPH Alphabets, digits special symbol Constants, Variables, Keywords Instructions Program

2 C CHARACTER SET ALPHABETS - A,B…………Z a,b………….z
DIGITS – 0,1,2,3,4,5,6,7,8,9 SPECIAL SYMBOLS - ? # $ % & * ()+ - \ = _ | : ;etc.. WHITE SPACES-Blank space,Tab,New line

3 TRIGRAPH CHARACTERS Many non-English keyboards do not support all the characters. For that C introduces the concept of “trigraph” sequences to provide a way to enter certain characters that are not available on some keyboards. Each trigraph sequence consists of three characters(two questionmark followed by another character). Ex.keyword not support square brackets, Ex. Trigraph Sequence Translation ??=, ??/ #,\ ??( , ??) [, ]

4 C TOKENS TOKENS VARIABLES CONSTANTS STRING KEYWORDS SPECIAL SYMBOL
OPERATORS

5 KEYWORDS AND IDENTIFIERS
All keyword have fixed meanings and meanings cannot be changed. Ex, break,else Identifiers refer to the names of variable, functions and arrays. These are user defined names and consist of sequence of letters and digits Rules:- First char must be alphabet. Contain letters, digits, underscore not white space, keyword.

6 DIFFERENCE BETWEEN CONSTANTS & VARIABLES
CONSTANT is a quantity that doesn’t change. VARIABLE is a quantity that value can be changed respectively. For example : 3X + Y = 20 Since 3 and 20 can not change, they are called constants, where as the quantities X & Y can vary or change hence are called variables.

7 TYPES OF C CONSTANTS C Constants Primary Constants Secondary Constants
Integer Constants Real Constants Character Constants String constants Escape sequence Array, Pointer , Structure , Union Enum etc.

8 INTEGER CONSTANTS - sequence of digits Three types Decimal: set of digits,0 through 9 123, -87, 0, <- valid $1000, , (20,000) <-Invalid Octal: combination of 0 to 7 with leading zero. i.e. 075, 051 are octal Hexadecimal:sequence of digits 0-9,A..F/a..f ….. Preceded by 0x or 0X like 0x2, 0x3A, 0Xe5,etc are hexadecimal numbers.

9 REAL CONSTANTS(FLOATING POINT)
- to represent varying entity like prices. it contain fractional parts. in decimal notation , , , etc. In exponential notation(or scientific) may be written as e2 also valid More 0.65e4 ,12e-2, 3.18E3. -> Should the following be valid ? 1.5E2.5 (YES / NO ) ?

10 SINGLE CHARACTER CONSTANTS
-a single character enclosed within a pair of single quote marks I.e ‘y’ , ‘4’, ‘;’ , ‘ ‘, etc. - character constants have integer values known as ASCII (American Standard Code for Information Interchange) values. i.e. printf(“%d”,’a’); will print no. 97, the ascii value of the letter a. While printf(“%c”,97); will print --- a *error in book statement instead of ’97’ it should be only 97

11 STRING CONSTANTS -sequence of characters enclosed in double quotes like “hello!” , “hi 18”, “well done”, “a” Remember that “x” and ‘x’ is different because ‘x’ has equivalent integer value in ASCII. String constants are normally used like displaying menu/messages.

12 BACKSLASH CHARACTER CONSTANTS
- used in output functions… - ‘\n’ stands for new line character - ‘\b’ for back space - ‘\t’ for making horizontal tab all above represents one character, although they consist of two chars. These char combination are known as “escape sequences”

13 VARIABLES A specific place where specific data is stored
variable name : to access/use the data stored at the specific place. A variable is a data name that may be used to store a data value i.e. you want to store two numbers 423 and 54. No No2 423 54

14 RULES FOR DEFINING A VARIABLE
1. They must begin with a letter & no special symbols are used without underscore.( _ ) i.e. total, mark1, ave_mark (Valid) 3mark, 345 (Invalid) 2. The length should not be normally more than 8 characters, since only the first 8 characters are treated as significant by the compiler. i.e. average_weight & average_height will be treated same.

15 RULES FOR DEFINING A VARIABLE
3. Uppercase and lowercase are significant. i.e. the variable Total is not the same as total or TOTAL. 4. The variable name should not be a keyword. i.e. a person name should not be a vocabulary spelling … 5. White space is not allowed. i.e. variable name ‘my total’ is invalid.

16 DATA TYPES Classes of data types : Primary data types
User defined data types Derived data types Basically C supports four Primary data types :- integer (int) , character (char), floating point (float) , double precision floating point (double).

17 PRIMARY DATA TYPES TYPE SIZE RANGE Char 1 byte -128 to 127
Int byte -32,768 to 32,767 Float byte 3.4e-38 to 3.4e+38 Double byte 1.7e-308 to 1.7e+308 Long int byte -232 to 232 Long double byte +/- 3.4*104932

18 QUALIFIER Signed : Indicates that the data can be positive or negative
Unsigned : Indicates that data to store is positive only… Short : Data to store will require less memory Long : Data to store will require more memory…

19 RANGE OF DATA TYPE 1 –32768 to 32767. ( from -215 to 215) SIGN BIT
So, here first bit is used for sign. Means if it is 0 then +ve no and 1 then –ve no. so, only other 15 bits are used for magnitude. And so that range is –32768 to 1 SIGN BIT

20 TYPE SHORT FORM SYMBOL character char %c Signed integer int %d Unsigned int Same %u real float %f double %lf Long double %Lf Signed long int %ld Unsigned long int %lu

21 DECLARATION OF VARIABLES
data_type v1,v2,….,vn; Where v1,v2, … vn are variable names. i.e. int maximum; will have two bytes memory allocated and the name ‘maximum’ associated with it. (by default the int is considered as signed, so range to ) i.e. unsigned int age; then 2 bytes allocated but the range will be 0 to

22 ASSIGNING VALUES TO VARIABLE
assignment operator int num1,num2,sum; sum = num1 + num2; No1=no2=no3; also possible… int no1=10; also possible …. Initialization at the time of declaration. char choice; choice = ‘y’; or scanf(“%c”,&choice);

23 USER DEFINED TYPE DECLARATION
Type definition that allows programmers to define an identifier/name that would represent an existing data type…. general form: typedef type identifier; i.e. typedef int marks_inc So, now onward when we require to store marks of c subject we will create variable of type marks_inc like, marks_inc m_stu1; typedef just increase readability via creating meaningful data type names, it can’t create a new datatype.

24 ENUMERATED DATA TYPE Suppose u want to store week days like Sunday, Monday,…, So, u know the possible values in advance …. Can be done using enumerated data type enum identifier {value1,value2,..}; i.e enum day {Mon,Tue,Wed,Thur,Fri,Sat,Sun}; enum day week_st; So, here week_st can have any possible value from the list

25 CONTINUING ENUM Here by default
Enumeration constant Mon is assigned 0, Tue assigned 1, Wed is assigned 2, and so on. However automatic assignments can be overridden by ….. enum day {Mon=10,Tue,Wed,…..}; Now As Mon is having 10, Tue will have one more 11, Wed will have 12, and so on. Q. int x; x = Wed – Mon; x = ?

26 VARIABLE’S STORAGE CLASS
Provides information about the location and visibility/scope of a variable. There are four storage class specifiers auto,register,static,extern. auto variables - defined within a function …. gets memory when the function is executing ……destroys when the function is over …..local to that function so can’t be used in outside function…. Gets garbage initialized..

27 …GLOABAL the variable declare outside any function before main known as global variable. It can be used in all the functions after the declaration of it. Note :: Global is External variable… External and static variable are initialized to zero by default… .while auto variable contains garbage .. Until they are initialized.

28 DECLARING A IDENTIFIER AS CONSTANT
Suppose u want to make some identifier whose value need not to be changed during the execution … const int class_size = 40; So, you can use const qualifier. This ensures that x= class_size; valid class_size = 10; invalid because as class_size is constant and can’t change it’s value.

29 VARIABLE AS VOLATILE a variable’s value may be changed at any time by some external sources (from outside the program). i.e. volatile int date; So, the value of date may be altered by some external factors … the compiler will examine the value of the variable each time it is encountered to see whether it is changed by other.

30 OVERFLOW OF DATA - when the value of a variable is either too big or too small for the data type to hold… - ‘C compiler does not provide any warning or indication of integer overflow. - Programmer must take care for the type and range of input possible

31 DEFINING SYMBOLIC CONSTANTS
- if some constant value is used at many places in the program… Like value of pi So, if we write the actual constant at each places then the problem can be - modification to do at each place if require - understanding the program like STRENGTH can be 50 and MAX_MARKS can also 50….

32 #DEFINE #define is used to define symbolic constants in our program.
We face two problems if we are using some numbers in the program at many places. 1. Problem in modification of the program. 2. Problem in understanding of program. By using the #define macro we can overcome these two problems.

33 THE GENERAL FORMAT OF #DEFINE
A constant can be defined as follows: #define symbolic-name value of constant Valid examples are: #define PI #define MAX 100

34 RULES APPLY TO #DEFINE 1.Symbolic name have the same form as variable names. But usually we are using CAPITALS for symbolic names. But that is not a rule. #define MAX 200 2.No blank space between the pound sign’#’ and the word define is permitted. # define MAX 200 <- Not permitted 3.’#’ must be the first character in the line. 4.A blank space is required between #define and symbolic name and between the symbolic name and value.

35 CONTINUE… 5.#define statements must not end with a semicolon.
#define PI ; <- Not valid 6.After definition, the symbolic name should not be assigned any other value within the program using an assignment statement. i.e. #define STRENGTH 100 main() { STRENGTH = 200; } Is illegal.

36 CONTINUE… 7.Symbolic names are NOT declared for data types. Its data type depends on the type of constant. 8.#define statements may appear anywhere in the program but before it is referenced in the program.


Download ppt "C AS A LANGUAGE Interface between computer & human being. ALPHABETS"

Similar presentations


Ads by Google