Professional Documents
Culture Documents
Bottom-up design: In bottom-up approach, system design starts with the lowest
level of components, which are then interconnected to get higher level components.
This process continues till, we get the complete program.
Modular approach
Modular programming (also referred to as modular architecture) is a general
programming concept. It involves separating a program’s functions into independent
pieces or building blocks, each containing all the parts needed to execute a single
aspect of the functionality. Together, the modules make up the executable application
program.
[2] History of C
C was developed by Dennis Ritchie on a DEC PDP-11 machine that used the Unix
operating system. C is the advanced version of an older language called BCPL. BCPL was
developed by Martin Richards, and it influenced a language called B, which was invented
by Ken Thompson. B led to the development of C in the 1970s.
For many years, C was supplied with the Unix operating system. It was first described in
The C Programming Language by Brian Kernighan and Dennis Ritchie. In the summer of
1983 a committee was established to create an ANSI (American National Standards
Institute) standard that would define the C language. The standardization process took six
years (much longer than anyone reasonably expected).
The ANSI C standard was finally adopted in December 1989, with the first copies
becoming available in early 1990. The standard was also adopted by ISO (International
Standards Organization), and the resulting standard was called as ANSI/ISO Standard C. In
1995, Amendment 1 to the C standard was adopted, which added several new library
functions. The 1989 standard for C, along with Amendment 1, became a base document for
Standard C++. The version of C defined by the 1989 standard is called as C89.
However, work on C continued quietly along. The end result was the 1999 standard for C,
usually referred to as C99. The C99 standardization committee focused on two main areas:
the addition of several numeric libraries and the development of some special-use, but
highly innovative, new features, such as variable-length arrays and the restrict pointer
qualifier. This is the version of C in widest use, it is currently accepted by all C compilers,
and it forms the basis for C++.
[3] Importance of C
C programming is a general-purpose, procedural programming language developed at
AT&T Bell Labs by Dennis Ritchie in the early 1970s. A successor of the B programming
language, it was developed to overcome the challenges of BASIC, B, and BPCL
programming languages.
Despite the emergence of numerous new languages like Java, Python, JavaScript, and PHP,
the popularity of C is not hampered. In fact, these languages have borrowed many of their
basic features from C.
Documentation
Link
Definition
Global Declarations
Main functions
Subprograms
Figure: Basic Structure Of C Program
a) Documentation Section
The documentation section is the part of the program where the programmer gives the details
associated with the program. He usually gives the name of the program, the details of the
author and other details like the time of coding and description. It gives anyone reading the
code the overview of the code.
Example
/*
File Name: Helloworld.c
date: 03/10/2022
description: a program to display hello world no input needed
*/
Example
#include<stdio.h>
c) Definition Section
In this section, we define different constants. The keyword define is used in this part.
#define PI=3.14
d) Global Declaration Section
This part of the code is the part where the global variables are declared. All the global variable
used are declared in this part. The user-defined functions are also declared in this part of the
code.
int main(void)
{
int a=10;
printf(" %d", a);
return 0;
}
Floating-Point Types
The following table provides the details of standard floating-point types with storage sizes
and value ranges and their precision:
Type Storage Value range Precision
size
float 4 byte 1.2E-38 to 3.4E+38 6 decimal places
double 8 byte 2.3E-308 to 1.7E+308 15 decimal places
long double 10 byte 3.4E-4932 to 1.1E+4932 19 decimal places
[6] Variables
A variable is a name given to a storage area in main memory. Each variable has a data
type, which determines its size in memory; the range of values; and the set of operations
that can be applied to the variable. C supports following basic variable types −
Type Description
char Typically a single octet(one byte). This is an integer type.
int The most natural size of integer for the machine.
float A single-precision floating point value.
double A double-precision floating point value.
void Represents the absence of type.
A variable definition tells the compiler where and how much storage to create for the
variable. The syntax of variable definition is given below−
type variable_list;
Here, type is a valid C data type such as char, int, float, double, bool, or any user-defined
data type and variable_list is identifier name. Some valid declarations are shown here −
int i, j, k;
char c, ch;
float f, salary;
double d;
The array is another kind of variable that is used in C. An array is a collection of same data
type elements.
Rules for Constructing Variable Names
A variable name is any combination of 1 to 31 alphabets, digits or underscores. Some
compilers allow variable names whose length could be up to 247 characters.
The first character in the variable name must be an alphabet or underscore.
No commas or blanks are allowed within a variable name.
No special symbol other than an underscore (as in gross_sal) can be used in a
variable name.
It should be a keyword.
Uppercase and lowercase symbols are different.
[7] Constants
A constant is an entity that doesn’t change whereas a variable is an entity that may change.
Constants can be of any of the basic data types.
There are four basic types of constants in C:
integer constants
floating-point constants
character constants
string constants.
a) Integer Constants
An integer constant is a sequence integer digits. It can be written in three number systems:
decimal, octal and hexadecimal. Several valid decimal integer constants are shown below.
0 1 743 5280 32767 9999
The following decimal integer constants are written incorrectly for the reasons stated.
12,245 illegal character (, ).
36.0 illegal character (.).
10 20 30 illegal character (blank space).
123-45-6789 illegal character (-).
0900 the first digit cannot be a zero.
An octal integer constant is made by digits 01234567. However the first digit must be 0.
EXAMPLE 0 01 0743 077777
The following octal integer constants are written incorrectly for the reasons stated.
743 Does not begin with 0.
05280 Illegal digit (8).
0777.777 Illegal character ( .).
A hexadecimal integer constant must begin with either 0x or 0X. It can consists any
combination of digits from the sets 0 through 9 and a through f.
EXAMPLE 0x 0X1 0X7FFF 0xabcd
b) Floating-Point Constants
A floating-point constant is a base-10 number that contains either a decimal point or an
exponent (or both).
EXAMPLE: Several valid floating-point constants are shown below.
0. 1. 0.2 827.602
5000. 0.00074 12.3 31 5.0066
2E-8 0.006e-3 1.6667E+8 .12121212e12
The following are not valid floating-point constants for the reasons stated.
1 Either a decimal point or an exponent must be present.
1,000.0 Illegal character (, ).
2E+10.2 The exponent must be an integer quantity (it cannot contain a
decimal point).
3E 10 Illegal character (blank space) in the exponent.
c) Character Constants
Character constants are enclosed between single quotes. For example, 'a' and '%' are
both character constants. C defines both multibyte characters, which consist of one or
more bytes, and wide characters (which are usually 16 bits long).
To specify a multibyte character, enclose the characters within single quotes, for
example, 'xy'. To specify a wide character constant, precede the character with an L.
For example:
wchar_t wc;
wc = L'A';
Here, wc is assigned the wide-character constant equivalent of A. The type of wide
characters is wchar_t, which is defined in the <stddef.h> header file, and is not a built-
in type.
d) String Constants
A string constant consists of sequence of characters, enclosed in (double) quotation
marks.EXAMPLE "green India” , "270-32-3456"
The compiler automatically places a null character (\0) at the end of every string
constant. Remember that a character constant (e.g., ‘A’ ) and the single-character
string constant ("A") are not equivalent. Also remember that a character constant has
an equivalent integer value, whereas a single-character string constant does not have
an equivalent integer value.
[9] Modifiers
Modifiers are the keywords to modify the default properties of int and char data types.
There are two types of type modifiers:
1. Size modifiers – short, long
2. Sign modifiers – signed, unsigned
They can be further sub-divided into these four data type modifiers :
1. long / long long
2. short
3. signed
4. unsigned
The modifier short and long can be applied to int type to get types short int and long int.
The modifier long can be applied to double to get the long double which stores extended
precision floating point number. In fact long is the only type modifier that can be applied
to double.
The modifiers signed and unsigned can be applied to char and integer types. When the
modifiers unsigned is used the number is always positive, and when signed is used number
may be positive or negative. If the sign modifier is not mentioned in integers, then by
default signed modifier is assumed. If the sign modifier is not mentioned for char type, then
whether the char type is signed or unsigned is machine dependent. The range of values for
signed data types is less than that of unsigned type. This is because in signed type, the
leftmost bit is used to represent the sign, while in unsigned type this bit is also used to
represent the value.
1. short It allows user to store small integer values from -32768 to 32767.
short int a = 18;
2. long It allows user to stores very large number (something like 9 Million Trillion)
from -9223372036854775808 to 9223372036854775807. Syntax “long long” is used
instead of “long int”.
long long a = 827337203685421584;
3. signed It is default modifier of int and char data type if no modifier is specified. It
says that user can store negative and positive values.
signed int a = -544;
signed int b = 544;
/* Both of the statements have same meaning even without "signed" modifier*/
4. unsigned When user intends to store only positive values in the given data type (int
and char).
unsigned int a = 486;
[10] Identifier
identifiers are names given to various program elements, such as variables, functions and
arrays. Identifiers consist of letters and digits, except that the first character must be a
letter. Both upper- and lowercase letters are permitted and are treated differently.
The underscore character ( - ) can also be included, and is considered to be a letter. An
underscore is often used in the middle of an identifier. An identifier may also begin with an
underscore.
EXAMPLE The following names are valid identifiers.
X, Y12, sum_1, _temperature, names, area, tax_rate, TABLE.
The following names are not valid identifiers for the reasons stated.
4th The first character must be a letter.
“x” Illegal characters (“).
order-no Illegal character (-).
Tax rate Illegal character (blank space).
An identifier can be arbitrarily long. Some compilers accept only the first 8 characters, and
other accept typically, 31 characters.
[11] Keywords
Keywords are the words whose meaning is fix to the C compiler. The keywords cannot be
used as variable names because if we do so we are trying to assign a new meaning to the
keyword, which is not allowed by the computer.
The standard keywords are
auto extern sizeof break
float static case for
Struct char goto switch
const if Typedef continue
int union default long
unsigned do register void
double return Volatile else
short while enum signed
Some compilers may also include some or all of the following keywords.
ada far Near asm
fortran pascal entry huge
[12] EXPRESSIONS
An expression represents a single data item, such as a number or a character. The expression
may consist of a constant, a variable, an array element or a reference to a function. It may
also consist of some combination of such entities, interconnected by one or more operators.
Expressions can also represent logical conditions that are either true or false.
EXAMPLE a + b, x = y, c = a + b, x <= y
[13] STATEMENTS
When c compiler found a statement it performs some action. There are three types of
statements in C. They are expression statements, compound statements and control
statements.
An expression statement consists of an expression followed by a semicolon. EXAMPLE
a = 3;, c = a + b ; ++i;
printf ("Area = %f area) ;
A compound statement consists of several individual statements enclosed within a pair of
braces { }. The individual statements may themselves be expression statements, compound
statements or control statements. Unlike an expression statement, a compound statement
does not end with a semicolon.
EXAMPLE
{
p i = 3.141593;
circumference = 2. * p i * radius;
area = p i * radius * radius;
}
Control statements are used to perform logical decision. Many control statements require
other statements within them example.
EXAMPLE 2.30 The following control statement creates a conditional loop in which
several actions are executed repeatedly, until some particular condition is satisfied.
while (count <= n) {
printf ( “%d”, x ) ;
++count;
}