Introduction to C Programming

Post on 17-Feb-2016

214 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

GFG

Transcript

Character Set The characters & symbols that a C program

can understand & accept. It is the combination of alphabet or character,

digit, special characters & white spaces (empty space).Letter: A – Z (Uppercase) & a – z (Lowercase)Digit: 0 – 9Special Characters: total 30 special charactersEmpty Space/White Space: horizontal, newline

tab, carriage return, form feed etc.

Cont’d Special Characters: -

comma , Period . Colon : Semicolon ; Question Mark ? Single Quote ‘ Double Quote “ Left Parenthesis ( Right Parenthesis ) Left Bracket [ Right Bracket ] Left Brace { Right Brace } Left angle bracket < Right angle bracket >

Special Characters: - Equal to sign = Exclamation Mark ! Vertical Bar | Slash/Forward Slash / Backslash \ Tilde Symbol ~ Plus Sign + Minus/Hyphen – Asterisk Sign * Hash Sign # %age Sign % Caret Sign ^ Ampersand Sign & “At the rate” sign @ Underscore Sign _

Delimiters In C PL, there are some special character used for special

syntactic meaning & these are called C delimiters. There are five delimiters: -

: Used for label entry( ) Used for expression & enclosing the

arguments in the function declaration[ ] Used for describing the size for array{ } Used for beginning & ending of function,

blocks & main program; Used at the end of every C statement except

control structure statements.

Keywords C language has some reserve words which can not

be used as variables or identifiers. These reserved words are keywords.

There are 40 keyword among which 32 are used for High Level Programming (standard keywords).

& remaining 8 are used for Low Level Programming (optional keywords).

Cont’d

auto break case char constcontinue default do double elseenum extern float for gotoif int long register returnshort signed sizeofstatic structswitch typedef unionunsigned voidvolatile while

Standard Keywords

Cont’d

ada far nearasm fortran pascalentry huge

Optional Keywords

Identifiers There are some words or names which

identify whether it is a constant or variable. These are the data names used by the programmer.

Identifier gives us the unique identification having unique sequence of character used for special purpose.

Rules for Identifiers It must be from the character set (unique). Blank Spaces are not allowed. It should not be a reserve word or keyword. They are always case sensitive. The character “_” underscore from the character set should

not be used as an identifier. It should be within the alphabets. eg. pay_rate is valid but pay_rate_ is invalid.

The length of an identifier should not be long (max. 32 char.). Hyphen (-) should not be used in an identifier. Always avoid a single char. Like a, m etc. eg: - simple

interest it should be “si”.

Constants When you either enter the data for input or to

assign the data to some identifier, then there be need of some storage space, so that entered or assigned data can be processed in a meaningful way. So the processed data be stored in two forms. These two forms are called constant or variable.

Those quantities whose value does not vary during the execution of the program i.e. value is fixed.

Types of Constant Constant

1) Numeric : - a) Integer b) Real/FloatInteger Real/Float

Decimal Octal Hexadecimal with without exponent exponent

2) Character (Non – numeric) : - single string Backslash character

Backslash CharacterAlso called “Escape Sequence”.

○ ‘\a’ or “\a” :- To ring a beep.○ ‘\b’ or “\b” :- It moves one space back.○ ‘\n’ or “\n” :- Move control to next line.○ ‘\f’ or “\f” :-Form feed (move one page next). Used in the printing

the hard copy only.○ ‘\t’ or “\t” :- Horizontal Tab (it moves eight spaces of tab).○ ‘\v’ or “\v” :- Vertical Tab (it moves eight lines down).○ ‘\r’ or “\r” :- Carriage Return (it replaces a word or string from the

beginning of the other string)○ ‘\’ ’ or “\’ ” :- It displays a single quote in output statement.○ ‘\” ’ or “\” ” :- It displays a double quote in output statement.○ ‘\?’ or “\?” :- It displays question mark.○ ‘\0’ or “\0” :- Null Character (it tells us the end of the string).

Variables Those quantities whose value can vary

during the execution of the program.

eg: - int high, low, result[20];

Data Types The description of nature of data either in

numeric forms (integer or real) or in character forms (single or string).

Types of data types: - Primary/Scalar/standard/Fundamental/SimpleSecondary/Derived/Structured Data TypeUser defined/Enumerated/Typedef Data TypeEmpty/Void Data TypePointer Data Type.

Primary/ Scalar/ standard/Fundamental/ Simple Data Type Used for representing a single value

only. These are divided into four categories: -

Integer data type (2 bytes size)Float data type (4 bytes size)Double (8 bytes size) or long float (10 bytes

size)Character data type (1 byte size).

Secondary/Derived/Structured Data Type

These are derived from the scalar data type by adding some additional relationship with the various elements of the primary or scalar data types.

Used for representing a single or multiple values. These are divided into three categories:

Arrays & StringsStructuresUnions

User defined/Enumerated/ Typedef Data Type Used for type definition i.e. allows to the users to define a variable or an identifier, which is used for representation of existing data types.

Enumerated can be defined as:enum identifier {v1, v2, v3, ……, vn};

Typedef can be defined as: typedef data-type identifier;

Empty/Void Data Type Used in the user-defined function or sub-programs. Used when the function sub-program returns nothing. Used when a function or sub-programs have not any

argument in it.

Pointer Data Type Used to handle the data at their memory addresses.

Declaring & Initializing Variables Note: - Study in the Practical Lab

Thank You!!!

top related