You are on page 1of 14

Umera Anjum

Software: Collection of programs

Program: Collection of instructions.

Instruction: To give instruction for operating system

OS (Operating System): Used to convert the high-level language to user understandable language
and vice versa.

* High level programming language is a user interface, it can be understood by human being. Ex: c,
c++, java, oracle etc.

* Programming language is a special kind of instruction which is mainly used to communicate with
the computer.

* Converting High level to user understandable language is known as Translator.

* To convert the High-Level Programming language to user understandable language we need


following process: (Translator of 3 Types)

1. Compiler (In single step process, Takes Less Time, Shows error at once)

2. Interpreter (Step by Step, takes more time to process, Shows error line by line)

3. Assembly (Converts language to Computer understandable language)

* Low level language instruction is given in symbolic form like mov a, b; & add a, b; etc.

* High Level Programming language: is syntonically equal to English and easy to understand. Ex: C,
C++, Java, Oracle etc.

* Low Level Programming Language: In this programming language, we have to give the instruction
in symbolic form and not easy to remember. Ex: 8086..

C – Programming Language:

* It is Structural, Procedure oriented and High-level programming language.

* Procedure oriented means dividing an application into sub module.

* Structural Programming means designing an application in block format (i.e., from top to bottom
of the program)

Why C??? Application:


 C is Simple (Easy to Understand) and fast
 Portable (carrying information from one to another)
 Mid-level language

Umera Anjum
Umera Anjum

 Platform (Dependent and Independent) & Hardware independent.

History of C:
 1950 – Forton (formula Translator) Alga (Algorithm Logic – 1958)
 1960 (International Committee) – ALGOL 60 [Algorithm – Solving problems in step by step]
 1963 (National Committee) – CPL (Combined Programmable Language)
 1967 Martin Richard (1Man Committee) – BCPL (Basic Combined Programming Language)
 1970 Ken Thomson, AT & T Bells Labs in USA – B Language (Basic)
AT & T – American Telephony & Telegraphy
 1972 by Dennis Ritchie, AT & T Bells Lab – C Language

Where C Stands.??

Computer Language: is a software or a pre -application

1. Machine Oriented, ex: Assembly, Machine- Better Machine efficiency

2. Program Oriented, Ex: Basic, forton, pascal, cobal

Machine oriented is used for Micro controller based and it is Low Level Language.

Program Oriented is used for Running OS and it is High Level Language.

Beginning of C:

English C
Alphabets, digits, Word, Number, Sentence, Alphabets, Digits, SP Symbols, constants,
Paragraphs variables, Keywords, Statements or Instruction
Program etc.

* Constants: the value cannot be changed during execution. we have Alphanumeric constants
(Character) and Numeric constants (Integer-without floating point, Float- with fractional path).

C Constants:
Primary Constants Secondary Constants
Variables, Integers, Real, characters Pointer, String, Structure, Array, UNION, Enum,
etc.

* Pointer Which points the memory location and it holds the value of memory.

* Array is nothing but collection of similar data.

* Collection of characters which are enclosed in a single quote is called String.

* Collection of similar data is called Structures.

* Change of data is nothing buy Enum.

* Different data with similar type is called Union.

Umera Anjum
Umera Anjum

Integer Constants:

Ex: 421, -62, +45, 4096 these are integers

Rules:

 No Decimal point, Ex:72.0


 May be positive or negative (Default Sign for Integer is Positive)
 No commas and space
 Valid Range: -32768 to +32767

Real Constants:

Ex: 427.62, +24.297, -0.00254

Rules:

 Must Contain a Decimal Point


 May be positive or negative (Default +ve)
 No commas and Space.
 Valid Range: 3.4*1038 to 3.4*1038
Real Exponent:
2.475 : L – 02475 E1 = 02475*10^1 R – 24.75E-1 = 24075*10^-1
24075 – Matissa, E, e – Exponential

Forms of Real Constants

Fractional Form Exponential Form


427.62 4.2762 E2 (E2 – 10^2)
+24.295 2.4295 e1 (e1 – 10^1)
-0.00254 2.54 e-3 (e-3 – 10^-3)

Character Constant:

Ex: ‘A’, ‘M’, ‘3’, ‘+’

Rule:

 A single character enclosed in a pair of single quote (‘…’)

Variable Names and Entity r\Rules for building:

 First character must be am alphabets, Reset can be alphabets, digits or underscore( _ )


Ex: POP 98, si_int
 Length <= 8 (usually)
 No commas or space
 Variable names are case sensitive
Ex: abc ABC Abc aBc AbC

C Keyword:
Keywords - Language related words with pre-defined meaning. 32 Keyword are used they are:

Umera Anjum
Umera Anjum

Auto Static IF
Else Void Int (Integer)
Char (Character) Continue Do
Goto Short Long
Near Register Return
While Unsigned Union
Typedef Switch Struct (structure)
For Far Float
Extern Enum Double
Default Case Break
Const (Constant) Signed

* Keyword has a Fixed meaning it cannot change its value and keyword has a special meaning.

* Reserved words are used for future purpose.

* Variable is an entity it can change the value during the execution time.

* Printf() is used for output function

* Scanf() is used for input function

* In C language each and every column should end with semicolon ( ; )

Declaration Variable:

float p,r,SI

Int n Variable Declaration


Shortcut Controllers:

P=1000.50 F2 – Save

Ctrl + F9 – Execution
N=3 Initialization Alt + x – to Exit

Alt + F5 – To Execute the o/p onscreen


r = 15.5
Alt + F9 – compiling the program

SI = p*N*r/100

printf(“%f”,SI)

Turbo C++ window:

#include <stdio.h>

Header File

Pre-processors

Converters:

Converters are used to convert the given source code into the object code. they are two types of
converters

1. Interpreters
2. Compiler

Umera Anjum
Umera Anjum

Interpreter:

This converter converts the given source into object wide line by line, it is used in the software like
DBase, VV

Compiler:

This converts he source code into the object code at a time, it is used in the software like Forton, C,
C++, etc.

ASCII:

(American Standard Code for Information Interchange)

* 0-255 Formats.

A-65 a-97
. .
. .
Z-90 z-122

Data Type:
Data types are of four types:

1. Basic and Primary Data Type (int, float, char)


2. Derived or Secondary data type (Array, function, pointers)
3. User Defined Data Type (Structure, union, Enum, typed if)
4. Empty data type (Void)

INT (Integer):

This data type is used to declare the variables to store integer values. every integer variable required
two bytes of memory (i.e.,16bits – 8,8)
Num
%d is the data conversion character (or) integer value. 8 8
2byte
Ex: int num (whereas, int – data type and num – variable)

Float:

This data type is used to declare the variables to store the floating values. every float variable
requires 4 bytes of memory (i.e.,32bits)

%f is the data conversion character to accept or display the floating value.

Ex: float val

String:

A group of characters is called String.

%S is the data conversion character to accept display a single string value.

Structure of a C Program:
#include <stdio.h>

Umera Anjum
Umera Anjum

void main()

{ //starting of program

variable declaration;

……………..

………….. Body of Program

………….

} //Ending of program

Rules to write the C Program:

1. Every program should start with main function - main()


2. Every program should contain only one main() function.
3. Entered Statements in a small case letters.
4. every C statement must end with semicolon ( ; )

** Array can store large amount of data but union can store one data at a time. **

Escape Sequences:
* \n denotes the new line character. i.e., it leaves the present and execute the next line

* \t is used to skip or jump the cursor horizontally or one tab position

printf(“\n\t Hello”)
the above representation is used to print the output on the screen

* \a is used to alert the user for giving a sound.

Program Model:

//Sample Program ---- Comment

#include<stdio.h> -----Pre-processor Directives

Void main ()

{ -----Starting of program

int i=20;

printf(“value %d”,i);

} -------------Ending og program

* Void doesn’t return any value.

* Main() is an identifier, represent starting of program

Types of Header files used with Pre-processor:


 <stdio.h>

Umera Anjum
Umera Anjum

 math.h
 string.h
 stdlib.h
 graphic.h

Comment:

First statement in the program is known as comment. The comment in the program will increase
the readability of a program

The comment statement are ignored by the compiler (or) execution.

we can define any number of comment statements in a single program.

The comments must be defined as two types.

1. single line
Syntax: // simple program
/*simple program*/
2. Multi-line comment
Syntax: /*simple program
simple program*/

* scanf(): This is one of the input function which is used to accept the values, while program
execution (or) at run time.

Syntax:
scanf(“formted strings”,&variables list);

Ex: Scanf(“%d %d”, &I,&j);

Note: “&” denote the address of the variable.

* printf(): Data on the output device and it is predefined value

Syntax: printf (“formatted specifies”, no. of arguments);

Format Specifiers:
printf(“text”); %d 1,2,3,…. (integer)
%f .01,0.1,0.2,…. (float values)
%c A,b,c,D,d… (Characters)
This is the standard formatted output function. this function displays the given text/value on to the
standard output device.

Ex: printf(“hello”); - Output: hello

**Printf() equation follows Stack Method i.e., Last In First Out (LIFO)**

Printf() Examples:

 Printf(“%d,%d,%d”,10,20,30); - Output: 10,20,30


 Printf(“%d,%d,%d”,10,20); - Output: 10 20 garbage Values
 Printf(“%d,%d”,10,20,30); - Output: 10 20 (30 will be ignored)
 Printf(“%d,hello,%d”,10,20); - Output: 10 hello 20

Umera Anjum
Umera Anjum

 Printf(“%d,hello,%d”,10,20,); - Output: Error (After 20 we have taken


comma which means it is waiting for
another response.. which displays error)

Example Program:

Void main()

i=1;

printf(“%d”,i);

Output: Error (Reason: Variable is not Declared in Program, to avoid error int i; should be declared)

* Operators are special kind of symbols to perform specific operation.

Types of Operators:

1. Arithmetic operators (Ex: +, --, *, /, %)


2. Relation operator
3. Logical operator
4. Increment (or) Decrement operator
5. Conditional operator
6. comma operator
7. Bitwise operator
i. & (Bitwise AND Operator)
ii. / (Bitwise OR)
iii. >> (Bitwise Right Shift)
iv. << (Bitwise Left Shift)
v. % (Modulus Division)

Arithmetic Operator:

This operator is used to find the solution on the variables.

Ex: var=a+b-c*d;

Relation Operator:

The operator is used to check the condition either less than (or) Greater than

Ex: int i;

i=s

Umera Anjum
Umera Anjum

if(i<5)

printf(“I”)

Logical Operator:

AND, OR, NOR are the logical operators

It is the operator used to performs logical operations

AND (&&): performs logical AND operation

Ex: if(i=3 && j=4)


{
----------;
-----------;
}
OR (!!) performs logical OR operation
NOT (!) performs NOT operation
Increment Operator (++): used to increase the variable value by 1.
Decrement Operator (- -): used to decrease the variable value by 1.
Increment (++) operators are of two types:
1. Post increment (i++)
2. Pre-Increment (++i)
Decrement (--) operators:
1. Post Decrement (i--)
2. Pre-Decrement (--i)

Note: In post increment, we assigned the value and increment


In pre-increment, first I increase the value/variable then assigned the value/variable.

Examples (i++, ++i, i- -, - -i) : if i = 5 (First it performs Pre-inc/Pre-Dec)


 i++ + ++i + i++; Output: 19
 ++i + ++i + i++ + ++i; Output: 30
 i-- + --i + i-- + --i; Output: 12
 i++ + --i + ++i + --i + i++ - --i + --i + ; Output:29

Conditional Operator:
Also known as Ternary Operator.
In this the control first execute then expression.

Syntax: Expressions? statement1: statement2;


True False

Ex: i=j=k? N=2:M=3;

Umera Anjum
Umera Anjum

Control Flow Statements:


i. Declaration Statement/Selection Statements (i.e., If, if-else, multiple-if)
ii. Iterative/Loop Statement (i.e., While, For, do-while)
iii. Continue & Break Statements / Jumping Statements

Declaration Statements:
i. If Statement:
Syntax:
Case-I: if(Condition) Case-II: if(Condition)
{ body;
body;
}
Case-I: When the condition is True it goes to body of the program & if the condition is False it comes
out of the body
Ex: if(5>2)
{
Printf(“good”);
Printf(“bye”);
} Output: goodbye
Case-II: In this the compiler make (construct) the body of the program.
Ex1: if(5>2) Compiler Construct: if(5>2) {
Printf(“good”); printf(“good”); {
Printf(“bye”); printf(“bye”); } Output: goodbye
Ex2: if(5<2) Compiler Construct: if(5<2) {
Printf(“good”); printf(“good”); {
Printf(“bye”); printf(“bye”); } Output: bye

ii. if-else Statement:


Syntax: if(Condition)
{
body;
}
else {
body;
}
** In Syntax if the IF condition is False it goes to Else Statement, if condition is True it goes
to body of program.

Ex1: if(5>2) { Ex2: if(5>2) {


Printf(“hello”); printf(“hello”); “
Printf(“world”); } else {
else { printf(“how are you”);
printf(“bye”); } Output: helloworld printf(“hi”); } Output: hello hi
**In Ex2 after the Else statement we have not given end statement (“ } ”) so, compiler
constructs body and prints the output.

Umera Anjum
Umera Anjum

Example Program: /** To Calculate the subject marks using IF-Else **/
#include<stdio.h>
void main()
{
int sub1,sub2,sub3,total;
float average;
printf("enter sub1,sub2,sub3 marks:");
scanf("%d%d%d",&sub1,&sub2,&sub3);
total=sub1+sub2+sub3;
average=total/3;
if(average>75)
{
printf("distinction");
}
else
{
if(average>70<60)
printf("Total: %d FC",total);
}
}

Iterative Statements:
i. While Loop:
Syntax: while (Condition)
{
body;
}
i++/i--;
**In this loop first while check the condition if condition is True enters into the body of the
program and come out of the loop after performing Increment/Decrement again checks the
condition... performs the same operation until the condition becomes False

Example Program: /** Print the values from n values **/

void main()
{
int i,n;
printf ("enter the number of values to be print, n = ");
scanf("%d",&n);
i=0;
while(i<=n)
{
printf("%d\n",i);
i++;
}
}

Umera Anjum
Umera Anjum

Example Program 2: /** Print the values from n values in Decrement order **/
#include<stdio.h>
void main()
{
int i,n;
printf ("enter the number of values to be print, n = ");
scanf("%d",&n);
i=0;
while(i<=n)
{
printf("%d\n",n);
n--;
}
}

Example Program 3: /** Print the values from given values **/
(Increment) (Decrement)
#include<stdio.h> #include<stdio.h>
void main() void main()
{ {
int i,n; int i,n;
printf ("enter i,n values:"); printf ("enter i,n values:");
scanf("%d%d",&i,&n); scanf("%d%d",&i,&n);
while(i<=n) while(i>=n)
{ {
printf("%d\n",i); printf("%d\n",i);
i++; i++;
} }
} }

Example Program 4: /** Print the table for given value **/

void main()
{
int i=1,n;

Umera Anjum
Umera Anjum

printf ("enter the n value:");


scanf("%d",&n);
while(i<=10)
{
printf("%d*%d=%d\n",n,i,n*i);
i++;
}

ii. For Loop:


Syntax: for (initialization; condition; ++/- -)
{
body;
}

**In this loop first initialize and then check the condition if condition is True enters into
the execute the program and if condition is False comes out of the loop. If the condition
is True it Increment/Decrements and check the condition until condition become false.
Ex: Print n values
void main()
{
int i;
for (i=1; i<=6; i++)
{
printf(“%d”,i);
}
} Output: 1 2 3 4 5 6

For Loop While Loop


For( ; ; ) – Infinite Loop While() – Error
For( ; 0 ; ) – 1 time rotation While(0) – No rotation
i=0; While(1) – infinite loop
fo( ; i ; ) – 0 rotations
less time to execute (Reason: Statement in one More time to execute (Reason: Jumping of
Sentence) Loops takes place, different statement need to
give)

iii. do - while Loop:


Syntax: do
{
body;
}
while(Condition);
}

**In this loop first it print the statement and then check the condition**

Umera Anjum
Umera Anjum

Ex: void main()


{
do
{
int i=1;
printf(“%d”,i);
}
while(i<=n);
}

Umera Anjum

You might also like