Programming in C: Presentation Created by Sukhadev SK
Programming in C: Presentation Created by Sukhadev SK
Programming in C: Presentation Created by Sukhadev SK
Programming is one way to communicate with computer system to solve our problems...
Introduction To C Language
History
C is inherited from BCPL and B Language Developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories. This language was created for a specific purpose: to design the UNIX operating system. The American National Standards Institute (ANSI) formed a committee in 1983 to establish a standard definition of C. This committee approved a version of C in 1989 which is known as ANSI C. C Language is called Middle Level Language, because it can be used to develop low level software to any kind of business applications and graphics also.
Features Of C Language
- C is a powerful, flexible language that provides fast program execution
INSTRUCTIONS
PROGRAM
Components C Language
1. Character set of C language 2. Keywords: There are only 32 Keywords 3. Variables & Identifiers 4. Constants
5. Data Types
6. Operators 7. Types of Expression/Statements
8. Tokens
9. Compound statement 10. Type Casting
C language is compiled language and its compiler is available at free of cost
Components C Language
1. Character set of C Language A to Z Alphabets a to z Alphabets 0 to 9 Digits Special Chars Blank Space Total 26 26 10 31 01 == 94
!@#$%^&*()_+-*/\|?{}[]<>,.:;'~`
Components C Language
2. Keywords
Are the reserved words, which have predefined meaning associated with them. - There are only 32 keywords in the C language. - Following table lists the keywords of the C language.
auto double int struct
break
case char const continue default do
else
enum extern float for goto if
long
register return short signed sizeof static
switch
typedef union unsigned void volatile while
Components C Language
3. Variables
Are the memory location names which are used to store data and whose value changes during program execution.
Rules to name the variables 1. Variable name must begin with an alphabet or an underscore 2. Except underscore no other special characters are allowed 3. Variable name can contain alphabet, digits and underscore 4. Keywords are not used to name the variable 5. Minimum of 8 characters and maximum of 32 char length is recommended 6. Variable name should not contain any blank space
Valid Variable Names
marks, sub1, roll_no avg, total, sum2 Invalid Variable Names ser no Reason Blank space is used 1marks Reason Begins with number roll#no Reason Special char used int Reason int is keyword
Identifiers are the names given to variables, arrays, functions, structures etc
Components C Language
4. Constants
Are the actual values in the expression whose meaning does not changes during program execution.
CONSTANTS
Numeric Constants
Text Constants
Integer Constants
Examples: 450 -32450 1000
Real Constants
Examples: 44.5666 0.2255 29.00 -0.255
String Constants
Examples:
Ugar Sri Ram 123greetings
String: Is combination of more than one characters with some definite meaning
Components C Language
5. Data Types
C provides a standard, minimal set of basic data types. Sometimes these are called "primitive" types, of fundamental data types, which are used to define the type of data that variable can hold. There are five fundamental data types available in C language, they are: 1. Integer 2. Character 3. Floating type 4. Double precision floating type 5. Void
Data Type Integer type Valid name in C Size in bytes int 2 Range of values -32768 to +32767
char float
double
1 4
8
void means nothing, it is used in function return type specifier where function is not returning anything to the calling function
Components C Language
5.1 Using Data type modifiers.
Data Type Name in C
unsigned char unsigned int short int unsigned short int long int
Size in Bytes
1 2 1 1 4
Range of values
0 to 255 0 to 65535 -128 to 127 0 to 255 -2147483648 to 2147483647
4
10
0 to 4294967295
3.4 e-4932 to 3.4 e+4932
Data Type modifiers, do not change the meaning of data type, they change only size
Components C Language
6. Operators An operator is a symbol which helps the user to command the computer to do a certain mathematical or logical manipulations. C has a rich set of operators which can be classified as: 1. Arithmetic operators 2. Relational Operators 3. Logical Operators 4. Assignment Operators 5. Increment and Decrement Operators 6. Conditional Operator 7. Bitwise Operators 8. Special Operators
Components C Language
6.1 Arithmetic Operators All the basic arithmetic operations can be carried out in C using following operators, these are also called as binary operators as they operate on two operands.
Operator + * / % Meaning Addition or Unary Plus Subtraction or Unary Minus Multiplication Devision Modulus Operator
Note: Mod (%) operator gives reminder of Integer Division Division (/) Operator gives quotient of Integer Division
Components C Language
6.2 Relational Operators Used to compare the relationship between operands and bring out a decision and program accordingly. C supports the following relational operators.
Operator
> Greater than
<
>=
<=
==
!=
Components C Language
6.4 Logical Operators C has the following logical operators, they compare or evaluate logical and relational expressions. In simple they used to combine two or more relational expressions.
Operator Meaning NOT OPERATOR Expr1
FALSE
&&
||
AND
OR
Result
TRUE FALSE
NOT
LOGICAL TABLES
TRUE
OR OPERATOR Expr1
FALSE FALSE TRUE TRUE
Expr2
FALSE TRUE FALSE TRUE
Result
FALSE TRUE TRUE TRUE
TRUE
TRUE
TRUE