C Programming: DR Nazneen Akhter
C Programming: DR Nazneen Akhter
Dr Nazneen Akhter
Introduction
7. For Creating Compilers of different Languages which can take input from other language and convert it into lower level machine dependent
language.
8. C programming language can be used to design Operating System.
9. C programming language can be used to design Network Devices.
10. To design GUI Applications. Adobe Photoshop, one of the most popularly used photo editors since olden times, was created with the help of C.
11. Systems that require fast and direct access to hardware
12. Systems with limited resources (like memory)
13. Systems where performance is the most important attribute
14. Some examples are BIOS, Operating Systems, Embedded Systems, Real-time systems
Structure of a Program.
Document Section
It consists of comment lines giving name of the program and other details which the
program would like to letter.
Link Section
It provides instructions to the compiler to link functions from the system library.
Definition Section
It defines all symbolic constants.
Global Declaration Section
If a variable has to be used in more than one function then that variable will be defined as
a ‘global variable’ in this section.
Structure of a Program.
■ 1] Preprocessing:
■ 2] Compilation:
• Using a compiler program to convert expanded source code to assembly source code
■ 3] Assemble:
■ 4] Linking:
■ 5] Loading:
• Using a loader program to load the executable code into CPU for execution
Character set
Letters
The character that can be used to form words, numbers and
expressions depend upon the computer’s programming language. Uppercase A….Z
3. Special characters
4. White spaces White Spaces
The compiler ignores white spaces unless they are a part of a string Black space
constant. Horizontal tab
Special Characters
, comma & ampersand
. period ^ caret
: semicolon * asterisk
? question mark - minus sign
‘ apostrophe + plus sign
“ quotation mark < less than sign
! exclamation mark > greater than sign
| vertical bar ( left parenthesis
/ slash ) right parenthesis
\ backslash [ left bracket
~ tilde ] right bracket
_ underscore { left brace
$ dollar sign } right brace
% percent sign
# number sign
auto double int struct
Keywords
break else long switch
Every C is classified as either a
keyword or an identifier. case enum register typedef
Keywords serves as a basic building
blocks for program statement.
char extern return union
All keywords have fixed meanings
and their meanings cannot be const float short unsigned
changed.
All keywords must be written in
continue for signed void
lowercase.
do if static while
Identifier
■ The variety of datatype available allow the programmer to select the type
appropriate to the needs of the application as well as the machine
char: The most basic data type in C. It stores a single character and requires a
single byte of memory in almost all compilers.
■
■
float: It is used to store decimal numbers (numbers with floating point value)
with single precision.
■
Integer constant
• An integer constant refers to a sequence of digits
• There are three types of integers, namely, decimal, octal and
hexadecimal
• e.g. 123, 78
• Decimal integer consists of a set of digits, 0 through 9, preceded by an
optional + or – sign
• Embedded space, commas and non-digit characters are not permitted
between digits
• An octal integer constant consists of any combination of digits from the
set 0 through 7 with a leading 0
• The sequence of digits preceded by a 0x or a 0X is considered as
hexadecimal integers. They may also include alphabets A through F
or a through f. the letters A through F represents numbers 10 to 15
Constants
Real constant
Constant Meanings
• Integer numbers are inadequate to represent quantities that vary continuously, such as \a Audible alert (bell)
distances, heights, temperatures, prices and so on.
\b Back space
• These quantities are represented by fractional parts like 228.35
•
\f Form feed
These are called real constants
• e.g. 123.78, 487.908 \n New line
Single character constant \r Carriage return
• A single character constant simply contains a single character enclosed within a pairs of single
quote marks \t Horizontal tab
• e.g. ‘s’, ‘7’ \v Vertical tab
String constant
\’ Single quote
• It is a sequence of characters enclosed in double quotes
\” Double quote
• The characters may be letters, numbers, special characters and blank spaces
•
\? Question mark
e.g. “Hello World..!!!”
Backslash character constants \\ Backslash
• C supports some special backslash character constants that are used in output functions \0 Null
• These are called as escape sequences
Variables