0% found this document useful (0 votes)
4 views64 pages

Latest

The document outlines a comprehensive C-Language course curriculum, covering topics such as computer basics, programming languages, algorithms, flowcharts, and C-Language features. It explains fundamental concepts of computer hardware and software, types of programming languages, and the importance of algorithms and flowcharts in problem-solving. Additionally, it provides insights into number systems and their significance in computing.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views64 pages

Latest

The document outlines a comprehensive C-Language course curriculum, covering topics such as computer basics, programming languages, algorithms, flowcharts, and C-Language features. It explains fundamental concepts of computer hardware and software, types of programming languages, and the importance of algorithms and flowcharts in problem-solving. Additionally, it provides insights into number systems and their significance in computing.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 64

C-Language Material

COURSE CONENTS
Sl.No Particulars Page No’s
01 Course Introduction
02 Typing Software
03 Computer Basics
04 Basics Shortcut Keys
05 Number System
06 Algorithms and Flowcharts
07 Types of Programming Languages
08 C-Language History
09 Why Use C , Features and Applications Of C
10 C-Language Software Environment
11 Character Sets
12 Implementation of C Program
13 Basic Programs
14 C-Language Tokens
15 Structure of C Program
16 Built In Functions
17 Escape Sequence Characters
18 C-Language Input/ Output Functions
19 C-Language Control Statements
20 Type Conversions
21 Strings
22 Arrays

Sirisha Devi -C/o Bright Computer Education ,Sattenapalli Page 1


C-Language Material

23 Structures
24 Unions
25 Typedef ,Enum and Bitfields
26 Functions
27 Storage Classes
28 Pointers
29 Dynamic Memory Allocation
30 Files
31 Command Line Arguments
32 C Preprocessor Directives
33 C-Language Graphics

COMPUTER BASICS
Computer Stands For-
Common Operating Machine particularly used for technical , education and
research

Definition:- A computer is an electronic device that receives input, stores or


processes the input as per user instructions and provides output in desired format.
Computer Advantages:-
 High Speed
 Storage Capacity
 Accuracy
 Versatility
 Reliability
 Automation

Sirisha Devi -C/o Bright Computer Education ,Sattenapalli Page 2


C-Language Material

Block Diagram of Digital Computer:-

1. Input Unit:- Input unit receive data or instructions through input devices.
The various input devices are: keyboard ,mouse , Scanner ,joystick ,Micro
Phone ,Light Pen , CC Camera etc.
Keyboard and mouse are standard input devices.
2. Output Unit:- output unit display result on output devices.
Monitor is a standard output device.
Various Output Devices:
1.Monitors(Softcopy output device): It is a standard output
device.
2.Printers (Hardcopy output Device)
3.Speakers (Voice output Device)
4.Projectors (Softcopy Output Device)

Sirisha Devi -C/o Bright Computer Education ,Sattenapalli Page 3


C-Language Material

3. CPU(Central Processing Unit):- CPU is considered as the brain of the

computer. CPU performs all types of data processing operations. It stores data,
intermediate results and instructions(program). It controls the operation of all
parts of computer.

Components of CPU:
1.Control Unit(CU)
2.Arithmetic & Logical Unit(ALU)
3.Memory Unit(MU)

1.control unit(CU) :- It controls communication and co-ordination between


input/output devices. (flow of data from one device to another device).
2.Arithmetic & logical Unit(ALU) :- It performs calculataion work.
3.memory unit(MU):- It stores data.

Computer Memory:-Computer memory is the storage space in computer


where data is to be processed and instructions required for processing are
stored.
Memory is primarily of three types
1.Primary Memory/Main Memory
2. Secondary Memory
3.Cache Memory
1.Primary Memory:-Primary memory holds only those data and instructions
on which computer is currently working. It
has limited capacity and data is lost when power is switched off. It is divided into
two sub categories.
1.RAM
2.ROM

Sirisha Devi -C/o Bright Computer Education ,Sattenapalli Page 4


C-Language Material

1.RAM:- RAM(Random Access Memory) is the internal memory of the CPU for
storing data, program and program result. It is read/write memory which stores
data until the machine is working. As soon as the machine is switched off, data is
erased.
2)ROM:-ROM stands for Read Only Memory. The memory from
which we can only read but cannot write on it.The information is stored
permanently in such memories during manufactures. A ROM, stores such
instructions that are required to start a computer.
II. Secondary Memory:-This type of memory is also known as external
memory or non-volatile. It is slower than main memory. These are used for
storing data/Information permanently.
Examples:- Hard Disk, Cd ,DVD ,pen drives etc.
III. Cache Memory:-Cache memory is a very high speed semiconductor
memory which can speed up CPU. It acts as a buffer between the CPU and main
memory.
Advantages:
1.Cache memory is faster than main memory.
2.It consumes less access time as compared to main memory.
3.It stores data for temporary use.
Units of Computer Memory Measurements:
1 Bit = Binary Digit (1,0)
8 Bits = 1 Byte
1024 Bytes = 1 KB (Kilo Byte)
1024 KB = 1 MB (Mega Byte)
1024 MB = 1 GB(Giga Byte)
1024 GB = 1 TB(Terra Byte)
1024 TB = 1 PB(Peta Byte)
1024 PB = 1 EB(Exa Byte)

Sirisha Devi -C/o Bright Computer Education ,Sattenapalli Page 5


C-Language Material

1024 EB = 1 ZB(Zetta Byte)


1024 ZB = 1 YB (Yotta Byte)
1024 YB = 1 (Bronto Byte)
1024 Bronto byte = 1 (Geop Byte)
Geop Byte is The Highest Memory Measurement Unit!!!

HARDWARE & SOFTWARE:-

Hardware:- Collection of physical components of a computer is called


hardware.
Software:- Collection of computer coded programs are called as software.
There are two types of software –
 System Software
 Application Software
System Software:- The system software is a collection of programs designed
to operate, control, and extend the processing capabilities of the computer itself.
System software is generally prepared by the computer manufacturers.
Some examples of system software are Operating System, Compilers, Interpreter,
Assemblers, etc.

Sirisha Devi -C/o Bright Computer Education ,Sattenapalli Page 6


C-Language Material

Application Software:- Application software products are designed to satisfy a

particular need of a particular environment.

Examples of Application software are the following −

 Payroll Software
 Student Record Software
 Inventory Management Software
 Income Tax Software
 Railways Reservation Software
 Microsoft Office Suite Software
 Microsoft Word , Microsoft Excel , Microsoft PowerPoint etc.

Types of Computer Programming Languages:


Computer languages are the languages through which user can communicate
with the computer by writing program instructions.

There are basically two types of computer programming languages given below:

1. Low level language


2. High level language

Low Level Languages


The programming languages that are very close to machine code (0s and 1s)
are called low-level programming languages.

The program instructions written in these languages are in binary form.

The examples of low-level languages are:

1. machine language
2. assembly language

1. Machine Language:- Machine language consists of binary numbers 0 and


1. Computer can understand this language without any translation. Its is very

Sirisha Devi -C/o Bright Computer Education ,Sattenapalli Page 7


C-Language Material

difficult, complex and even time consuming to write a program. If there is an


error in the program, then it becomes very difficult to detect it.

Advantage of Machine Language

The only advantage of machine language is that the program of machine


language runs very fast because no translation program is required for the
CPU.

Disadvantages:- Here are some of the main disadvantages of machine


languages:
1. Machine Dependent
2. Difficult to modify
3. Difficult to program

Assembly Level Language:- It is another low-level programming


language because the program instructions written in this language are close
to machine language.

Assembly language is also known as second generation of programming


language. In assembly language special symbols are used for programming
which are known as “Mnemonic Codes” .

Advantages:- Here are some of the main advantages of using assembly


language.

1. Easy to understand and use


2. Easier to locate and correct errors
3. Easy to modify
4. Efficiency of machine language.

Sirisha Devi -C/o Bright Computer Education ,Sattenapalli Page 8


C-Language Material

Disadvantages:- Here are some of the main disadvantages of using assembly


language.

1. Machine dependent
2. Machine level coding
3. Knowledge of hardware required

High Level Languages:- A language which is close to humans and far


from computer is known as High Level Language. It is based on English like
words. We can understand it very easily, but it is difficult to be understood by
the computer.

Advantages of High Level Languages


There are several advantages of high level programming languages. The most
important advantages are:

 Easy to learn
 Easy to understand
 Easy to write program
 Easy to detect and remove errors
 Built-in library functions
 Machine Independence

Limitation of High Level Language


There are two main limitation of high level languages are:

 Low efficiency
 Less flexibility

Sirisha Devi -C/o Bright Computer Education ,Sattenapalli Page 9


C-Language Material

Translators

Translators:- A program written in high-level language is called as

source code. To convert the source code into machine code, translators are
needed. A translator takes a program written in source language as input and
converts it into a program in target language as output.

Different type of translators

The different types of translator are as follows:

1. Compiler
2. Interpreter
3. Assembler

1. Compiler:- Compiler is a translator which is used to convert programs


in high-level language to low-level language at a time. It translates the entire
program and also reports the errors in source program encountered during the
translation.

Sirisha Devi -C/o Bright Computer Education ,Sattenapalli Page 10


C-Language Material

2. Interpreter:-Interpreter is a translator which is used to convert


programs in high-level language to low-level language. Interpreter
translates line by line and reports the error once it encountered during the
translation process.

3. Assembler:-Assembler is a translator which is used to translate the


assembly language code into machine language code.

Algorithms and Flowcharts


What is an algorithm? Explain Important properties or
features of algorithm.
Algorithm:- An algorithm is a step by step method of solving a problem. It is
commonly used for data processing, calculation and other related computer
and mathematical operations.

Sirisha Devi -C/o Bright Computer Education ,Sattenapalli Page 11


C-Language Material

Features of algorithm:

 It should be simple.
 Algorithms make our work easy in solving the problems.
 Every step is clearly described.
 Data flow is processed in top-down approach.
 Algorithms can easily be converted into flow charts.
 Errors can be easily detected.
 It is not dependent on any programming language, so it is easy to
understand for any one even without programming knowledge.
 By using algorithm the problem is divided into smaller pieces or steps, it
is easier for programmer to convert into actual program.

Limitations of algorithm:
1. Time Consuming
2. Difficult to show branching and looping
3. Al algorithm is not a computer program.
4. Big tasks are difficult to put in algorithm.

Sirisha Devi -C/o Bright Computer Education ,Sattenapalli Page 12


C-Language Material

Example1: Write an algorithm to add two numbers .


Step1: Start
Step2: Declare the variables x ,y and z
Step3: read variables x and y
Step4: Add x and y and assign this result to z.
z=x+y
Step5: Print Z
Step6: Stop

Example2: Write an algorithm to find the largest among two numbers

Step1: Start
Step2: declare variables a and b
Step3: Read variables a and b
Step4: if a>b
Then print “Big value is a”
Else
Then print “Big value is b”
Step5: Stop
Example3: Write an algorithm to find the largest among three
numbers.
Step 1: Start
Step 2: Declare variables a,b and c.
Step 3: Read variables a,b and c.
Step 4: If a>b
If a>c
Display a is the largest number.
Else

Sirisha Devi -C/o Bright Computer Education ,Sattenapalli Page 13


C-Language Material

Display c is the largest number.


Else
If b>c
Display b is the largest number.
Else
Display c is the greatest number.
Step 5: Stop

What is flow chart? Explain important properties or features ,


limitations ? Explain various symbols in drawing a flow chart?

Ans:-
Flowcharts: flowchart is a graphical representation of an algorithm. It is an
alternate technique for solving a problem.

Features of flowchart:
1.flowcharts provide a better way of pictorial representation of algorithm.

2.flow chart denotes the flow of data control.

3.problem solving is easy thus save time.

4. The flow chart helps in rectifying the errors easily.

Important points to draw the flowcharts:

1.Flowcharts should be clear ,neat and easy to follow.

2.flowchart should be logically correct.

3.flowchart should be verified for its validity with some test data.

Sirisha Devi -C/o Bright Computer Education ,Sattenapalli Page 14


C-Language Material

4.The direction of representation of flow of data should be in top-down


approach left right.

Limitations of flowcharts:
1.flowcharts are difficult to modify.

2.translation of flowchart into computer program is always not easy.

3.The drawing of flow chart is more than one sheet of paper, the connectors
are used for jointing different pages.

Symbols used in drawing a flow chart:-


1)Start-Stop Box:- It is used to indicate the beginning or the end of the
sequential steps.

Start Stop

2)Input/ Output Box:- It is used to read data from the user and to display
result on monitor.

Read Write
A,B,C A,B,C

3)Decision Box:- The decision box is used to make a condition. If the


decision box condition is true , then we go to true statement direction
otherwise we go to false direction in flow chart. A diamond symbol used for
this decision box.
Sirisha Devi -C/o Bright Computer Education ,Sattenapalli Page 15
C-Language Material

4) Assignment Box:- A rectangle is used to represent an assignment box.


It is also called process box. All type of assignment statements insert in this
box.

Z=x+y

5)Connectors:-A flow chart becomes too long to fit in a single


page. Connectors are used.

Sirisha Devi -C/o Bright Computer Education ,Sattenapalli Page 16


C-Language Material

Sirisha Devi -C/o Bright Computer Education ,Sattenapalli Page 17


C-Language Material

NUMBER SYSTEM
Number System is used to represent information in quantitative form.

type of number system:

1. Decimal Number System


2. Binary Number System
3. Octal Number System
4. Hexadecimal Number System

1.Decimal Number System:- The number system that we use in our day-
to-day life is the decimal number system. Decimal number system has base 10
as it uses 10 digits from 0 to 9. In decimal number system, the successive
positions to the left of the decimal point represent units, tens, hundreds,
thousands and so on.

Base Value: 10

Digits : 0 to 9

Ex:- 4576, 76879

2.Binary Number System:- In Binary system we have two digits 0 and 1.


Computer represents all kinds of data and information in binary numbers. It
includes audio , graphics , video ,text and numbers. The base of binary number
system is 2.

Base Value:2

Digits : 0,1

Ex:- 1101010, 11000

Sirisha Devi -C/o Bright Computer Education ,Sattenapalli Page 18


C-Language Material

3.Octal Number System:- An octal number system has eight digits


represented as 0,1,2,3,4,5,6,7. The base of octal number system is 8.

Base Value: 8

Digits : 0 to 7

Ex:- 034 ,045 ,067

4.Hexa Decimal Number System:- The hexa decimal system has 16-
Digits, which are represent as 0,1,23,4,5,6,7,8,9,A,B,C,D,E,F. The base of
hexadecimal number system is 16.

Base Value: 16
Digits : 0 to 9 and
10-A
11-B
12-C
13-D
14-E
15-F
Ex:- 0xA5 , 0X56
Convert Decimal Number System to Binary Number System
1) 45

2 | 45
2 22-1
2 11-0
2 5-1
2 2-1
1-0
(45)10 = (101101)2

2)120
2| 120
60-0
30-0
15-0
Sirisha Devi -C/o Bright Computer Education ,Sattenapalli Page 19
C-Language Material

7-1
3-1
1-1
(120)10 =(1111000)2

3) 178
2|178
89-0
44-1
22-0
11-0
5-1
2-1
1-0
(178)10=(10110010)2

Convert Binary Number System to Decimal Number System


1)101101

32 16 8 4 2 1
1 0 1 1 0 1
32+8+4+1=45

2) 1 1001

16 8 4 2 1
1 1 0 0 1
16+8+1=25

3)1111000

64 32 16 8 4 2 1
1 1 1 1 0 0 0
64+32+16+8=120

4) 101010001

Sirisha Devi -C/o Bright Computer Education ,Sattenapalli Page 20


C-Language Material

256 128 64 32 16 8 4 2 1
1 0 1 0 1 0 0 0 1
256+64+16+1=337

5)10101010

128 64 32 16 8 4 2 1
1 0 1 0 1 0 1 0
= 128+32+8+2=170

Convert Decimal Number System to Octal Number System


1) 70
8 | 70
8 8 -6
1-0
( 70)10 = ( 106)8

2)127
8|127
8 15-7
1-7
(127)10 = (177)8

3) 450
8 |450
8 56-2
7-0
(450)10 =(702)8

4) 615
8 | 615
76-7
9-4
1-1
(615)10=(1147)2

Sirisha Devi -C/o Bright Computer Education ,Sattenapalli Page 21


C-Language Material

5) 987
8|987
123-3
15-3
1-7
(987)10 = (1733)8
Convert octal number system to decimal Number System

1)106 64 8 1
1 0 6
64+6=70

2)1733
512 64 8 1
1 7 3 3
512+ 448+24+3=987

3)1147
512 64 8 1
1 1 4 7
512+64+32+7=615
Convert Decimal to hexa decimal number system
1)45
16 |45
2-13(D)
45=2D
2)95
16|95
5-15
95= 5F

3) 400
Sirisha Devi -C/o Bright Computer Education ,Sattenapalli Page 22
C-Language Material

16|400
25-0
1-9
400 =190

Convert Hexa Decimal Number system to Decimal


Number System
1) 2D = 16 1
2 D
32+13=45

2) 5F
16 1
5 F
80+15=95

3)256
256 16 1
1 9 0
=256+144=400

4) 315
256 16 1
3 1 5
789

Basics Shortcut Keys

1. Any Application Close->Alt+F4


2. Tally Close -> Q
3. C-Language Close->Alt+X
Sirisha Devi -C/o Bright Computer Education ,Sattenapalli Page 23
C-Language Material

4. Application Minimize,maximize,restore and close-> Alt+Space Bar


5. Maximize the minimized application or Switch one application to
another ->Alt+Tab
6. Application help->F1
7. Run ->(start)+r
8. My Computer -> start button+E
9. Search Files and folders-> start+F or F3
10. Show Desktop -> Start +D
11. Change File Name -> click on File and press F2
12. New -> Ctrl+N
13. Open-> Ctrl+o
14. Save -> Ctrl+S
15. Print -> Ctrl+P
16. Undo->Ctrl+Z (step Backward)
17. Redo-> Ctrl+Y (Step forward action)
18. Cut->Ctrl+X
19. Copy->Ctrl+C
20. Paste->Ctrl+v
21. Find->Ctrl+F
22. Replace->Ctrl+H
23. select all-> Ctrl+A
24. Refresh ->F5
Document Shortcut Keys(Word ,Wordpad)
25. Text Select -> Shift+Home or shift+end
26. Select more than one line -> shift+up arrow or
shift+down arrow
27. Bold Text-> Ctrl+B

Sirisha Devi -C/o Bright Computer Education ,Sattenapalli Page 24


C-Language Material

28. Italic Text-> Ctrl+I


29. Underline Text->Ctrl+U
30. Left -> Ctrl+L
31. Right->Ctrl+R
32. Center->Ctrl+E
33. Letter size increase-> Ctrl+Shift+>
34. Letter size decrease -> ctrl+Shift+<
35. Line spacing->Ctrl+1 or Ctrl+2 or Ctrl+5
36. Bullets-> ctrl+Shift+L
Menu ShortCut Keys
37. File Menu-> Alt+F
38. Edit Menu->Alt+E
39. Format Menu->Alt+O
40. View Menu->Alt+V
41. Help Menu->Alt+H
42. Keyboard shortcut for any application
For example: wordpad
start menu->programs->accessories->mouse right click on wordpad-
>properties->
Shortcut key: Type "W" letter
now shortcut key is: ctrl+alt+w
43. Desktop shortcut key for any application
start menu->programs->accessories->mouse right click on wordpad->send
to->Desktop create shortcut
44. Restart Computer-> Ctrl+Alt+Delete

C-LANGUAGE HISTORY

Sirisha Devi -C/o Bright Computer Education ,Sattenapalli Page 25


C-Language Material

C programming language was developed in 1972 by Dennis Ritchie at bell

laboratories of AT&T (American Telephone & Telegraph), located in the U.S.A.

Dennis Ritchie is known as the founder of the c language.

It was developed to overcome the problems of previous languages such as B,

BCPL, etc.

Initially, C language was developed to be used in UNIX operating system. It

inherits many features of previous languages such as B and BCPL.

Let's see the programming languages that were developed before C language.

Why Use C?

Sirisha Devi -C/o Bright Computer Education ,Sattenapalli Page 26


C-Language Material

C was initially used for system development work, particularly the programs
that make-up the operating system. C was adopted as a system development
language because it produces code that runs nearly as fast as the code written
in assembly language. Some examples of the use of C might be −
 Operating Systems
 Language Compilers
 Assemblers
 Text Editors
 Print Spoolers
 Network Drivers
 Modern Programs
 Databases
 Language Interpreters
 Utilities

Features of C:-

C is the widely used language. It provides many features that are given below.

1. Simple
2. Machine Independent or Portable
3. Mid-level programming language
4. structured programming language
5. Rich Library
6. Memory Management
7. Fast Speed
8. Pointers
9. Recursion

Sirisha Devi -C/o Bright Computer Education ,Sattenapalli Page 27


C-Language Material

10. Extensible

1) Simple:- C is a simple language in the sense that it provides a


structured approach (to break the problem into parts), the rich set of
library functions, data types, etc.

2) Machine Independent or Portable:- Unlike assembly language, c


programs can be executed on different machines with some machine specific
changes. Therefore, C is a machine independent language.
3) Mid-level programming language:- Although, C is intended to do
low-level programming. It is used to develop system applications such as
kernel, driver, etc. It also supports the features of a high-level language.
That is why it is known as mid-level language.

4) Structured programming language:- C is a structured


programming language in the sense that we can break the program into parts
using functions. So, it is easy to understand and modify. Functions also
provide code reusability.

5) Rich Library:- C provides a lot of inbuilt functions that make the


development fast.

6) Memory Management:- It supports the feature of dynamic memory


allocation. In C language, we can free the allocated memory at any time by
calling the free() function.

7) Speed:- The compilation and execution time of C language is fast since


there are lesser inbuilt functions and hence the lesser overhead.

Sirisha Devi -C/o Bright Computer Education ,Sattenapalli Page 28


C-Language Material

8) Pointer:-C provides the feature of pointers. We can directly interact with


the memory by using the pointers. We can use pointers for memory,
structures, functions, array, etc.

9) Recursion:- In C, we can call the function within the function. It provides


code reusability for every function. Recursion enables us to use the approach
of backtracking.

10) Extensible:- C language is extensible because it can easily adopt new


features.
Programming Rules:-A programmer while writing a program should
follow following rules.

1. Every program should have main() function.


2. C-Language statements should be terminated by a semi-colon.
3. All statements should be written in lowercase letters. Generally, uppercase
letters are used only for symbolic constants.
4. Blank spaces may be inserted between the words. This leads to
improvement in the readability of the statements. However , this is not
applicable while declaring a variable ,keyword ,constant and function.
5. It is not necessary to fix the position of statements in the program;i.e a
programmer can write the statement anywhere between the two braces
following the declaration part. The user can also write one or more
statements in one line separating them with a semicolon(;).Hence it is often
called free form language.
6. The opening and closing braces should be balanced. i.e . if opening braces
are four ; closing braces should also be four.

C-LANGUAGE SOFTWARE ENVIRONMENT

How to enter C-language editor


Sirisha Devi -C/o Bright Computer Education ,Sattenapalli Page 29
C-Language Material

My computer->goto C drive(c:\) ->turboc2-> click on Tc .exe


C-language Turbo C Editor
..........................................
1.Title Bar:- It display application name, minimize, maximize, restore and
close buttons.
2.Menu Bar:- It contains menus. Each menu contain no of options. Each
option contain some specific task.
3.Editor window:- It is used to create new program and open, modify the
already existing program.
4.Message window:- When you compiling the program if the program is not
successfully then display errors and warnings in message window.
5.Status bar:- It display status of the editor window with the help of short
cut keys.

File menu:-
1.Load:- It is used to open already existing programs.
2.pick:- It is used to open the recent opened and created programs list.

3.new:- It is used to create a new program.


4.save:- It is used to save the current program
c:\turboc2\noname.c
c:\turboc2\s1.c
5.write to:- to copy the current program with another name.
c:\turboc2\s2.c
6.directory:-It is used to see the specified directory programs list.

Sirisha Devi -C/o Bright Computer Education ,Sattenapalli Page 30


C-Language Material

7.change dir:- It is used to change one directory to another directory.


c:\turboc2\directory name
c:\turboc2\student
8.os shell:- shift from c-language editor to dos editor.
9.Quit:- It is used to close c-language editor.
C –Language Character Sets
The characters used to form words , numbers and expressions depend upon the
computer on which the program runs. The Characters in C are classified in the
following categories.

1. Upper Case Letters A to Z


2. Lower Case Letters a to z
3. 0 to 9
4. Horizontal Tab(space)(" \t ")
5. vertical space (" \n(new line) ")
6.some special symbols
a);(semicolon)
in c-language every line terminate with semi colon. semicolon is a line
terminator.
b) { -> (opening curly brace)

"}" ->closing curly brace


in c-language every program start with "{" and terminate with "}"
ex:-
main()
{
...............

Sirisha Devi -C/o Bright Computer Education ,Sattenapalli Page 31


C-Language Material

................
}

c) ( )-> parenthesis
parenthesis are used in conditions and functions
Ex:- if(a>b) here a>b is a condition
conditions are must and should enclosed with parenthesis
main()->here main is a function
add()-> here it is add function
d) # (hash)
in c-language (pre processor directive)
e) =
in c-language "= " is a assignment operator.
x=y+z; (y+z value is assigned to x variable)
i=10; ( 10 is assigned to i variable)
i=j; (j variable value is assigned to i variable )
f) ==("equal to" Operator)

i==10 (both i variable value and 10 are same)


x==y;(x,y are same)
g) %(percentage)
in c-language it is a modulas operator(remainder)
ex:- 10%3=1
25%2=1
/(divison)
ex:- 10/3=3
25/2=12

Sirisha Devi -C/o Bright Computer Education ,Sattenapalli Page 32


C-Language Material

10/2=5
9/3=3
i) *(astrick)
in c-language
1) multiplication(10*3=30)
2) it is also used as a pointer variable in c-language
(*i)-> here i is a pointer variable
j)&(ampersand)
in c-language
1)&&->logical and
Ex:- (i>j)&&(i>k)
2)&-> bitwise and (ex:-10&8)
3)&i-> address of i

k) |(pipe symbol)
in c-language
1) ||->logical OR
Ex:- (i,j)||(i<k)
2) | ->Bitwise OR
Ex:- 10|6
l) !
in c-language it is a "logical not"
!(10<8)
if condition is true then logical not returns false
if condition is false then logical not returns true
m)^(caret)
in c-language it is a "Bitwise exclusive OR"
Sirisha Devi -C/o Bright Computer Education ,Sattenapalli Page 33
C-Language Material

10^8 (Bitwise Exclusive Or)


n) in c-language single character must and should enclosed
with in single quotes(' ')
ex:- 's','0','h' etc
char ch='s';
o) in c-languge strings must and should enclosed with in double
quotes(" ")
ex: "java", "oracle"
p) [] ->square brackets
square brackets are used in array declarations. it indicates the array size.
ex:- a[5]
int marks[100];

q) ? and : are used as conditional operators in c-language

IMPLEMENTATION OF C PROGRAM
Steps for executing the c program:
1. Creation of program
2. Compilation of a program
3. Execution of a program
1. Creation of program:- Programs should be written in c editor. The
file name does not necessarily include extension of C. The default extension
is C. The user can also specify his/her own extension.

first we create a sample program in turboc editor


main()

Sirisha Devi -C/o Bright Computer Education ,Sattenapalli Page 34


C-Language Material

{
textcolor(14);
cprintf("welcome to c");
}
after create a program we save a program by using
file menu ->save
c:\turboc2\noname.c
c:\turboc2\s1.c

here s1.c file contains source code.


source code understand by user .But computer can't understand our source
code.
s1.c(source code)
2. Compilation of Program:- we compile the program by using alt+f9,
then the compiler check our program at a time , if the program is
successfully then compiler converts source code to object code.
s1.obj(object code)

if the program is not successfully then display errors and warnings in


message window.

3. Execution of a program (run):- we execute a program by using


ctrl+f9. Then create s1.exe file.
s1.c -> s1.obj->s1.exe-> s1.bak

source object machine back up


code code code code

C-LANGUAGE BASIC PROGRAMS


program1
W.a.p to display a message using printf()
main()
{
clrscr();

Sirisha Devi -C/o Bright Computer Education ,Sattenapalli Page 35


C-Language Material

printf("welcome to c-language ");


getch();
}
file menu->save-> c:\turboc2\noname.c
c:\turboc2\faculty1.c
compiling-> alt+f9
ctrl+f9(run)
Program2:-
W.a.p to display a message in colour format

main()
{
clrscr();
textcolor(10);
cprintf("C-language");
getch();
}

program3:
write a program for display an integer value
main()
{
int i=10;
clrscr();
printf("%d",i);
getch();
}
program4
write a program to display a float value
main()
{
float i=5.67;
clrscr();
printf("float value is:%f",i);
getch();
Sirisha Devi -C/o Bright Computer Education ,Sattenapalli Page 36
C-Language Material

program5:-
W.a.p to display a float value
main()
{
float i=6.8766;
clrscr();
printf("float value=%f\n",i);
printf("3 decimals value:%.3f",i);
getch();
}
Program6:
W.a.p to display a character
main()
{
char ch='l';
clrscr();
printf(" ch = %c",ch);
getch();
}

Program7:
W.a.p to display two integer values
main()
{
int i=90,j=45;
clrscr();
printf("%d\t%d",i,j);
getch();
}

Program 8:

Sirisha Devi -C/o Bright Computer Education ,Sattenapalli Page 37


C-Language Material

W.a.p to display two float values


main()
{
float i=23.34, j=4.5;
clrscr();
printf("%f \t %f",i,j);
getch();
}
Program9:
W.a.p to display different type of values with new line
("\n")

main()
{
int x=10;
float y=3.5;
char z='h';
clrscr();
printf("integer value is: x=%d\n",x);
printf("float value is :y=%f\n",y);
printf("z=%c\n",z);
getch();
}
Program 10:
W.a.p to display square value of given number
main()
{
int i=7;
clrscr();
printf("square value is=%d",i*i);
getch();
}
Program11:
W.a.p to display total, average of given two numbers
Sirisha Devi -C/o Bright Computer Education ,Sattenapalli Page 38
C-Language Material

main()
{
int m1=56,m2=89,m3=45;
int total;
float avg;
clrscr();
total=m1+m2+m3;
avg=total/3;
printf("Total Marks are=%d\n",total);
printf("Average Marks are=%f\n",avg);
}
Program12:
W.a.p to read value in meters and display centimers of the given
meter value.
main()
{
int m=9;
int cm;
clrscr();
cm=m*100;
printf("%d m=%d cm",m,cm);
getch();
}
Program13:

W.a.p to read meter value and convert to centimeters


main()
{
int cm=950;
float m;
clrscr();
m= (float)cm/100;
printf("%d cm= %.2f M",cm,m);
getch();
}
Sirisha Devi -C/o Bright Computer Education ,Sattenapalli Page 39
C-Language Material

Home Work
......................
1)W.a.p to read value in kilograms and convert to gms
main()
{
int kg=2;
int gms;
clrscr();
gms=kg*1000;
printf("%d kg=%d gms",kg,gms);
getch();
}
2) Grams to Kilograms

3) Celsius to Fahrenheit’s
main()
{
int C=1;
float F;
clrscr();
F=C*1.8+32;
printf("%dC=%.2fF",C,F);
getch();
}
4) Fahrenheit’s to Celsius
T(°C) = (T(°F) - 32) / 1.8

C-LANGUAGE TOKENS
Tokens:- The smallest individual units in a program are known as tokens.
1)variable

2)identifier

Sirisha Devi -C/o Bright Computer Education ,Sattenapalli Page 40


C-Language Material

3)keyword

4)operators

5)constants

6)data types

1)Variable
Variable:-It is a user defined name. It reserved some space in computer
memory to store a value.

A variable may take different values at different times during the


execution.

Rules:-
 A variable can have alphabets, digits, and underscore.
 A variable name can start with the alphabet, and underscore only. It
can't start with a digit.
 No commas ,blank spaces are allowed within a variable name.
 Keywords should not be used as variable names.
 the length of variable cannot exceed up to 8 characters long and some of
the "c" compilers can be recognized upto 31 characters long.

syntax for variable declaration


datatype variablename;
Ex:- int i;
float j;
char ch;
here i,j,ch are variables int,float ,char are data types.
Program1
Write a program to read an integer value at runtime

Sirisha Devi -C/o Bright Computer Education ,Sattenapalli Page 41


C-Language Material

main()
{
int i;
clrscr();
printf("enter a value");
scanf("%d",&i);
printf("the integer value is=%d",i);
getch();
}
2. write a program to display float value at runtime
main()
{
float i;
clrscr();
printf("enter a float value");
scanf("%f",&i);
printf("float value is=%f",i);
getch();
}
3. W.a.p to read and display a character
void main()
{
char ch;
clrscr();
printf("enter a character");
scanf("%c",&ch);
printf("the character is:%c",ch);

Sirisha Devi -C/o Bright Computer Education ,Sattenapalli Page 42


C-Language Material

getch();
}

4. W.a.p to read value at runtime and display square of given


number
main()
{
int i;
clrscr();
printf("enter a value");
scanf("%d",&i);
printf("square is=%d",(i*i));
getch();
}
5. W.a.p to display two float values at run time
main()
{
float x,y;
printf("enter two float values");
scanf("%f%f",&x,&y);
printf("%f\t%f",x,y);
}
6. W.a.p to read three subject marks at runtime and display
total and average values of given three numbers
main()
{
int sub1,sub2,sub3,total;
Sirisha Devi -C/o Bright Computer Education ,Sattenapalli Page 43
C-Language Material

float avg;
clrscr();
printf("Enter Three Subject Marks");
scanf("%d%d%d",&sub1,&sub2,&sub3);
total =sub1+sub2+sub3;
avg=total/3;
printf("Total Marks: %d\n",total);
printf("Average :%f",avg);
getch();
}
7. W.a.p to convert Meter value to Centimeters value
main()
{
float m,cm;
clrscr();
printf("Enter Meter value");
scanf("%f",&m);
cm=m*100;
printf("%.2fm=%.2fcm",m,cm);
getch();
}
8. W.a.p to convert Centimeters to Meters
main()
{
float cm,m;
clrscr();
printf("Enter Centimeters value");

Sirisha Devi -C/o Bright Computer Education ,Sattenapalli Page 44


C-Language Material

scanf("%f",&cm);
m=cm/100;
printf("%.2fcm=%.2fm",cm,m);
getch();
}
variable initilization
The variable receive the value at the time of declaration is called variable
initialization.
syntax:- datatype variable=value;
Ex:- int i=56;
float j=9.0;
program1
main()
{
int i=10;
clrscr();
printf("%d",i);
getch();
}
program2:-
main()
{
int i=67;
float j=8.9;
char k='s';
printf("i=%d\n",i);
printf("j=%f\n",j);

Sirisha Devi -C/o Bright Computer Education ,Sattenapalli Page 45


C-Language Material

printf("k=%c\n",k);
}
or
main()
{
int i=90;
float j=34.56;
char k='d';
clrscr();
printf("%d %.2f %c",i,j,k);
getch();
}

variable assignment
After initialization again the values are assigned to variables then this is called
variable assignment.
main()
{
int i=10; /*initilization*/
i=20; /*assignement*/
i=30;
clrscr(); /*assignment*/
printf("%d",i);
}
output:- i=30

chained assignment
i=j=k=10;

Sirisha Devi -C/o Bright Computer Education ,Sattenapalli Page 46


C-Language Material

k=10=> j=k;=> i=j;


program
main()
{
int i=10,j=20,k=30;
printf("%d\t%d\t%d",i,j,k);
i=j=k=50;
printf("%d\t%d\t%d",i,j,k);
getch();
}
const variable
Const variable can't access any changes of the variable.The variable receive
initial value as final value. So we can't modify const variables.
Ex:-
main()
{
const int i=10;
i=20;/*error*/
i=30;/*error*/
printf("%d",i);
}

volatile variable:- volatile variable can accept any changes of the variable.
main()
{
volatile int i=10;
i=20;

Sirisha Devi -C/o Bright Computer Education ,Sattenapalli Page 47


C-Language Material

i=30;
clrscr();
printf("%d",i);
}
Local variable:- The variable declared inside a function then that variable
is called local variable.local variables can't access by another functions.
local variables are used only that function.
main()
{
int i=10;
float j=20.23;
clrscr();
printf("local variable=%d\n",i);
printf("local variable=%f\n",j);
}
Global variable:- the variables are declared outside the main() then that
variables are called global variables.Global variables are used any where(all
functions)
int i=10; /*global variable*/
main()
{
int j=20; /*local variable*/
clrscr();
printf("local variable=%d\n",j);
printf("global variable=%d",i);
}

Sirisha Devi -C/o Bright Computer Education ,Sattenapalli Page 48


C-Language Material

problem:-3
int i=10;/*global*/
main()
{
int i=20;/*local*/
printf("%d\n",i);
}
In C-language the local variable and global variable declared with same
name then default the local variable display this means the local variable hide
the global variable.
This problem is solved by using scope resolution operator in C++ language.

w.a.p for display power of m to n


#include<math.h>
main()
{
int m,n,k;
clrscr();
printf("enter m value");
scanf("%d",&m);
printf("enter n value");
scanf("%d",&n);
k=pow(m,n);
printf("power(m,n)=%d",k);
getch();
}

Sirisha Devi -C/o Bright Computer Education ,Sattenapalli Page 49


C-Language Material

Identifiers:- A C identifier is a name used to identify a variable, function, or


any other user-defined item. An identifier starts with a letter A to Z, a to z, or an
underscore '_' followed by zero or more letters, underscores, and digits (0 to 9).

Keywords:- keyword is a predefined word or reserved word. Every keyword


have specific meaning . All keywords have fixed meanings they can't modified by
users. They can only used by users
White spaces are not allowed in keywords.
some keywords are int ,char ,float , long , if ,else, break ,switch ,for ,while
,do, case ,continue, default ,goto, struct ,typedef, enum ,const, volatile etc.

Constants
constants:- The constants in C are applicable to the values,which do not
change during the execution of a program. There are several types of constants
in C.
constants are divided into two types

1.numeric constants
1.integer constants:-These are the sequence of numbers from 0 to 9
without decimal points or fractional part or any other symbols.
ex:- int i=10;

Sirisha Devi -C/o Bright Computer Education ,Sattenapalli Page 50


C-Language Material

int m1=34,m2=45;

integer constants are classified into three types.


1.Decimal Integer constant
2.Octal Integer Constant
3.Hexa Decimal constant
2. Real constants:-Real constants are often known as floating point constants.
ex:- float i=5.6;
double i=67.89;
3.Character Constants:-Character constants are divided into two types
1.single character constants:-A character constant is a single
character.they are also represented with a single digit or a single symbol
enclosed within pair of single quote marks.
ex:- char ch='23';
char ch='s';
2.string constants:-String constants are sequence of charcters enclosed
withquote marks.the string may be a combination of all kinds of symbols.
char ch[10]="hello"; char ch[10]="13124234";

Operators:- "Operator is a symbol that tells the computer to perform some


mathematical or logical or other operations with operands."
operend is a value or variable.
Ex:- z=x+10;
+ ,= are operators
x,z,10 are operends
unary operator:-which operator operate with only single operand is called
unary operator.
Ex:- ++(increment),--(decrement)
Sirisha Devi -C/o Bright Computer Education ,Sattenapalli Page 51
C-Language Material

++i;
Binary operator:-Which operator operates with two operands are called
binary operators.
Ex:- +,-,*,/,%,&&,|| etc. are binary operators.
c-language operators are
1. arithmetic operators
2. logical operators
3. relational operators
4. conditional operators
5. assignment operators
6. increment or decrement operators
7. bitwise operators
1.Arithmetic operators:-These operators are used to perform fundamental
arithmetic operations. These operators are binary operators.
1.binary arithmetic operators
Operator Meaning
................. .................
+ Addition
- subtraction
* multiplication
/ division
% modulas or remainder
w.a.p to perform arithmetic operations with given two values
main()
{
int i,j;
clrscr();
Sirisha Devi -C/o Bright Computer Education ,Sattenapalli Page 52
C-Language Material

printf("enter two values");


scanf("%d%d",&i,&j);
printf("addition=%d\n",(i+j));
printf("subtraction=%d\n",(i-j));
printf("multiplication=%d\n",(i*j));
printf("divison=%d\n",(i/j));
printf("modulas=%d",(i%j));
getch();
}
unary minus(-):- Unary minus operator change positive sign to negative sign
value and negative sign value to positive sign value

main()
{
int i=-10,j=90;
clrscr();
printf("i=%d\n",-i);
printf("j=%d",-j);
getch();
}
Logical Operators
Sometimes, we have to check more than one conditions at a time then we use
logical operators
Logical operators are
logical and &&
logical OR ||
logical NOT !

Sirisha Devi -C/o Bright Computer Education ,Sattenapalli Page 53


C-Language Material

Logical AND(&&)
A B A&&B
......... ....
T T T
T F F
F T F
F F F
Logical Or(||)
A B A||B
................
T T T
T F T
F T T
F F F
...................
Logical NOT(!)
A !A
T->F
F->T
Program1:
main()
{
clrscr();
printf("%d\n",(10<100)&&(7!=7));
printf("%d\n",(5==5)||(9>10));
printf("%d",!(6>10));
getch();

Sirisha Devi -C/o Bright Computer Education ,Sattenapalli Page 54


C-Language Material

}
output:-
0 1 1
W.a.p to read 3 subject marks and to check student is pass or fail
main()
{
int m1,m2,m3;
printf("enter 3 subject marks");
scanf("%d%d%d",&m1,&m2,&m3);
if(m1>=35&&m2>=35&&m3>=35)
{
printf("pass");
}
else
{
printf("fail");
}
getch();
}
w.a.p to check the given charcter is vowel or consonent.
main()
{
char ch;
printf("enter a character");
scanf("%c",&ch);
if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')
{

Sirisha Devi -C/o Bright Computer Education ,Sattenapalli Page 55


C-Language Material

printf("vowel");
}
else
{
printf("consonent");
}
}

Relational Operators
Operator Meaning
............... ...............
> Greater Than
< less than
>= Greater than or equal to
<= Less than or equal to
== Equal to
!= Not Equal to
relational operators are used between any two or more operends for check
conditions. if the relation is true then it returns 1 value otherwise it returns
zero value.
main()
{
printf("%d\n",10<100);
printf("%d\n",12!=23);
printf("%d\n",5==5);
printf("%d\n",2>=10);
printf("%d\n",5<=10);
}

Sirisha Devi -C/o Bright Computer Education ,Sattenapalli Page 56


C-Language Material

Program2:
main()
{
int i=10,j=20,k=30;
i=j=k=5;
clrscr();
k=(i==k);
j=(i>k);
i=(j<=k);
printf("%d\t%d\t%d",i,j,k);
getch();
}

3.Conditional operators (? :)
Conditional operator is also called as 'ternary operator.' It is widely used to
execute condition in true part or in false part.
Syntax:
(exp1)?Exp2: exp3
(condition)?true statement :false statement
here exp1 is a condition if exp1 returns true then exp2 value is displayed
otherwise exp3 value is displayed.
Ex:-
res=(a>b)?a:b;
here the logical or relational operators are used to check condition.
w.a.p to find big value of two numbers by using conditional
operators
main()

Sirisha Devi -C/o Bright Computer Education ,Sattenapalli Page 57


C-Language Material

{
int a,b,big;
clrscr();
printf("enter two values");
scanf("%d%d",&a,&b);
big=(a>b)?a:b;
printf("big value is=%d",big);
getch();
}
w.a.p to find given no is positive or negitive by using conditional
operator
main()
{
int n;
clrscr();
printf("enter a value");
scanf("%d",&n);
(n>=0)?printf("positive"):printf("Negitive");
getch();
}

w.a.p to check given character is capital or small using ASCII


VALUES
A to Z--> 65 to 90
a to z 97 to 122
0 to 9 48 to 57
...........................................
Sirisha Devi -C/o Bright Computer Education ,Sattenapalli Page 58
C-Language Material

main()
{
char ch;
clrscr();
printf("enter a character");
scanf("%c",&ch);
(ch>=65&&ch<=90)?printf("capital") : printf("small");
getch();
}
w.a.p to check given no is even or odd by using conditional
operator
main()
{
int n;
printf("enter a value");
scanf("%d",&n);
(n%2==0)?printf("even") :printf("odd");
getch();
}
Home Work
W.a.p to check given year is leap year or not
main()
{
int y;
printf("enter year");
scanf("%d",&y);
(y%4==0)?printf("leap year"):printf("Non Leap Year");

Sirisha Devi -C/o Bright Computer Education ,Sattenapalli Page 59


C-Language Material

getch();
}
2)W.a.p to check given two numbers are equal or not by using
conditional operator
main()
{
int x,y;
printf("enter two values");
scanf("%d%d",&x,&y);
(x==y)?printf("same"):printf("different");
getch();
}
Assignment Operator(=):-This operator is used to store value into a
variable.It is used in 3 ways.
1.it is used to store a value into a variable ex:- int x=5;
2.it is used to store the value of a variable into another variable
int x=y;
3.it is used to store the value of the expression into the variable.
x=y+z-4;
short hand assignment operators
operator example
+= i+=10-> i=i+10
-= i-=10 -> i=i-10
*= i*=10 -> i=i*10
/= i/=10-> i=i/10
%= i%=10 ->i=i%10

Sirisha Devi -C/o Bright Computer Education ,Sattenapalli Page 60


C-Language Material

while using assignment operator (=) some times we may have same variable at
both sides of the operator. In such cases we can eliminate repetition of the
variable and use compact notation
main()
{
int i=10;
clrscr();
printf("Short hand operations are:\n");
printf(" %d\n", (i+=10));
printf("%d\n", (i-=10));
printf("%d\n", (i*=10));
printf("%d\n", (i/=10));
printf( "%d",(i%=10));
getch();
}
W.a.p to read two values and display swapping of given two
variable values

main()
{
int x,y;
clrscr();
printf("enter two values");
scanf("%d%d",&x,&y);
printf("before swapping %d \t %d",x,y);
x=x+y;
y=x-y;

Sirisha Devi -C/o Bright Computer Education ,Sattenapalli Page 61


C-Language Material

x=x-y;
printf("after swapping %d \t %d",x,y);
getch();
}
W.a.p to read two values and display swaping of given two
variable values
main()
{
int x,y,z;
clrscr();
printf("enter two values");
scanf("%d%d",&x,&y);
printf("before swapping %d \t %d",x,y);
z=x;
x=y;
y=z;
printf("after swapping %d \t %d",x,y);
getch();
}
Comma operator (,)
In c-language instead of " ;" comma(,) is also used as line terminator with some
rules
1.program declartion must and should terminate with semicolon
2.program ending line must terminate with semicolon.

main()
{

Sirisha Devi -C/o Bright Computer Education ,Sattenapalli Page 62


C-Language Material

int i;
clrscr(),
printf("enter a value"),
scanf("%d",&i),
printf("%d",i),
getch();
}
main()
{
int i=10,j=45,k=67;
i=j<k,
k=i>j,
j=i==k,
clrscr(),
textcolor(12),
cprintf("%d %d %d",i,j,k),
getch();
}

main()
{
int i;
i=10,
i=20,
clrscr(),
textcolor(10),
cprintf("%d",i),

Sirisha Devi -C/o Bright Computer Education ,Sattenapalli Page 63


C-Language Material

getch();
}

Sirisha Devi -C/o Bright Computer Education ,Sattenapalli Page 64

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy