You are on page 1of 12

Programing In C [SMT. V.B.

NANDOLA COMPUTER SCIECNE COLLEGE, BHACHA]

Chapter: - 1 Introduction of „C ‟
Q. 1 Write a short note on history of C.

 By 1960, number of computer languages had come into existence almost each for a
specific purpose. For Example: - COBOL (Common Business Oriented Language)
was being used for commercial Application, FORTRAN (Formula Transaction Language)
for engineering & scientific application and so on. At this stage people started thinking
for a general purpose language. Therefore, an International Committee was formed to
develop such a language. This committee comes out with a language called ALGOL-60.
However, ALGOL-60 never really become popular because it seemed too obstruct, too
general.
 To reduce this abstractness and generality a new language called Combined
Programming Language (CPL) was developed at Cambridge University. However, CPL
turned out to be so big, having so many features, that it was hard to learn and difficult
to implement.
 Basic Combined Programming Language (BCPL) was developed by Martin Richards at
Cambridge University aimed to solve this problem by bringing CPL down to its good
features. But unfortunately it turned out to be too less powerful and too specific.
 Meanwhile, Ken Thompson has developed language „B‟ as a further simplification of
CPL at AT&T‟s Bell Labs. But like BCPL B too turned out to be very specific.
 Dennis Ritchie inherited the features of B and BCPL in C, added some of his own and
developed the „C‟ language at AT&T Bell Laboratories of USA in 1972. Dennis Ritchie‟s
main achievement is the restoration of lost generality and still keeping it powerful.
 To Standardize C, American National Standards Institute (ANSI) appointed a technical
committee. It later came to be known as ANSI C. Later it is standardized by ISO
Committee to form ISO and ANSI C.

Year Language Developed By Remarks


1960 ALGOL International Committee Too General, Too abstract
1963 CPL Cambridge University Hard to learn, Difficult to
implement
1967 BCPL Martin Richards at Could deal with only specific
Cambridge University problems
1970 B Ken Thomson at AT&T Could deal with only specific
problems
1972 C Dennis Ritchie at AT&T Lost generality of BCPL and B
rested
1978 K&RC Kernighan and Ritchie
1989 ANSI C ANSI Committee ANSI Standards
1990 ISO C ISO Committee ISO Standards

Prepared by Mr. Pankaj M. Zalera 1


Programing In C [SMT. V.B. NANDOLA COMPUTER SCIECNE COLLEGE, BHACHA]

Q. 2 What is „C‟?
 „C‟ is a programming language developed at AT&T Bell Labs of USA in 1972.
 It was designed and written by Dennis Ritchie.
 „C‟ is a compatible language , because it can work on any platform(DOS/WINDOWS)
 „C‟ is Middle Level Language, because it is the combination of Higher Level
Language (Problem Oriented Language) and Lower Level Language
(Assembly/Machine Level Language).
 „C‟ supports both GUI (Graphical User Interface) and CLI (Command Line Interface)
environment.
 „C‟ having high probability, it means it is working on different hardware platforms.
 „C‟ is reliable because it contains necessary tools for solving user problems.
 Execution time very fast with respect to other languages that‟s why „C‟ has better
efficiency.
 „C‟ is a case-sensitive language
i.e. int a;
int A;
So, a and A both are different variables.
Q. 3 Write a short note on C Character Set.

 A character denotes any alphabet, digit or special symbols used to represent


information following table shows the valid alphabets, numbers and special symbols
allowed in C:

 Character Sets:

A, B, C,……..,Z
Alphabets
a, b, c,………,z
Digits 0, 1, 2,……….,9

Special Symbols { } [ ] < > + = - / \ @ # ? , . „ ‟ : % etc.

Q. 4 Write a short note on C Constants.

 Constants in C refer to fixed values that do not change the execution of program.
 There are basically two types of constants namely:
1. Numeric Constants
2. Character Constants

Prepared by Mr. Pankaj M. Zalera 2


Programing In C [SMT. V.B. NANDOLA COMPUTER SCIECNE COLLEGE, BHACHA]

Constants

Numeric Character

Integer Real Single String


Constants Constants Character Character
Constants Constants

 „C‟ supports basically Integer Constants, Real Constants and Character Constants.

1. Numeric Constant :

 There are two types of numeric constant namely:


A. Integer Constant.
B. Real Constant.

A. Integer Constant :-
 RULES:
 An integer constant must have at least one digit.
 It must not have a decimal point.
 It could be either positive or negative.
 If no sign precedes an integer constant it is assumed to be positive.
 No commas or blanks are allowed within an integer constant.
 The allowable range for integer is -32768 to +32767.
 Example of „int‟ constant
i.e. 3 
325 
45.5 -
10,000 -
40,000 much larger -
+32 
-5 
 There are three types of integers namely Decimal, Octal, Hexa-Decimal.

B. Real Constant :-

 The numbers containing fractional parts are as a Real Constant. It‟s also
called as a Floating Point Constant.
 RULES
 A Real Constant must have at least one digit.
 It must have a decimal point.
 It could be either positive or negative.
 Default sign is positive.
Prepared by Mr. Pankaj M. Zalera 3
Programing In C [SMT. V.B. NANDOLA COMPUTER SCIECNE COLLEGE, BHACHA]

 No commas or blanks are allowed within a real constant.


 The allowable range for real is -3.4 e 38 to +3.4 e 38
 A real numbers may also be expressed in exponential notation. The
general form of scientific notation is:
Mantissa e exponent
Whereas the mantissa is a real number expressed in decimal notation or an
integer. The exponent is an integer number with an optional plus [+] or
minus [-] sign.
 Default sign of mantissa or exponent part is positive.
 Example of Real/Float Constant
i.e. 15 
+15 
-15.2 
3,400.5 -
3 400.5 -
+340.75
-258.86
0.01 
41e8 
-3.2e8.2 -
2. Character Constant :
 There are basically two types of character constants namely :
A. Single Character Constant
B. String Character Constant
A. Single Character Constant :-
 A single character constant contain single character enclosed within a
pair of single quoted marks, is called as a single character constant.
 Example of Single Character Constant

i.e. ‟A‟ 
„A‟ -
‟AB‟ -
‟a‟ 
‟=‟ 
„12‟ -
‟1‟ 

 RULES:
 A character constant is either a single alphabet, a single digit or a single
special symbol enclosed within single inverted commas. Both the
inverted commas should point to the left.
 For Example:
‟A‟ is a valid character constant whereas „A” is not.
 The maximum length of a single character constant can be 1 character.
Prepared by Mr. Pankaj M. Zalera 4
Programing In C [SMT. V.B. NANDOLA COMPUTER SCIECNE COLLEGE, BHACHA]

B. String Character Constant :-

 A character constant contain either alphabets or digit or special symbol


enclosed within double inverted commas, is called as string character
constant.
 Example of String Character Constant
i.e. ”College” 
”123-456” 
‟5678910” -

Q. 5 What are different type of variable in „C‟, and also discuss variable
naming rules?
 Variable whose value constantly changing during the program execution.
 Keywords can‟t be taken as a variable.
 It is a temporary storage media for solving user‟s problem.
 Variable have two types:

Variable

Local Variable Global Variable


Class: Automatic Class: External
Inside main() Outside main()
 NOTE: Default value of Local & Global variable called garbage value.

 Example:-

Difference between Local & Global variable by program-

#include<stdio.h>
#include<conio.h>
int a=15; //Global type, Class: External
void main()
{
int a=10; //Local type, Class: Internal
clrscr();
printf(“\n Value of a: %d”,a); //Local
printf(“\n Value of a: %d”,::a); //External
getch();
}
 Output:-

Value of a: 10
Value of a: 15

 RULES:
 A variable name is any combination of 1 to 8 alphabets, digits or
underscores (_).
Prepared by Mr. Pankaj M. Zalera 5
Programing In C [SMT. V.B. NANDOLA COMPUTER SCIECNE COLLEGE, BHACHA]

 The first character in the variable name must be an alphabet.


 No commas or blanks are allowed within a variable name.
 No special symbol other than an underscore (e.g. gross_sal) can be used in
a variable name.
 „C‟ is case sensitive language. So, Capital and Small Letters are considered
as a different variable name.
e.g. int a;
int A;
 Length of name is up to 8 characters.
 It must not be a keyword.
 The above referred rules remain same for all types of variable.
e.g. Integer variables, Float variable and Character variable.

Q. 6 What is a variable? How to declare it?

 In „C‟, a quantity, which may vary during execution of program, is called as


a Variable.
 A variable can be used to store a value of any data type. That is, the name
has nothing to do with its type.
 The syntax of declaring variable is as follows:
Syntax:
datatype variable_1, variable_2, ….., variable_n;
Variable_1, Variable_2 are the names of variables separated by commas. A
declaration statement must end with a semicolon (;).
 For Example:-
int no;
char name;
float percentage;
 Here, int, char and float are the keyword to represent integer type,
character type and real type data respectively.
 Example:-
variable declaration:
int a;
char a; Primary type
float a;
char a[10]; //Array type Declaration
char *s; //pointer type Declaration
int a[10]; //Array type Declaration
struct student Secondary type
{
int roll_ no; members
char name[10];
}

Prepared by Mr. Pankaj M. Zalera 6


Programing In C [SMT. V.B. NANDOLA COMPUTER SCIECNE COLLEGE, BHACHA]

Q. 7 Explain the structure of „C‟ language.


or
Why the „C‟ language is called structure language.
 C program can be viewed as a group of building blocks called functions. A
function is a sub-routine that may include one or more statements
designed to perform specific task.
 C program may contain one or more section as referred here in below:
Programming Structure of „C‟
Document section [Comment line]
Link Section
Definition Section
Global Variable Declaration Section
main() function Section
{
Declaration Part
Executable Part
}
Sub-Program Section [User Define Function (UDF)]
{
Function-1
Function-2
Function-3
}

 Document Section:

 Comments are considered as documentation purpose.


 The document section consists a set of comment lines giving the name
of the program.
 Comments can‟t be compiled (process).
 Comments can‟t be nested.
 E.g.:-
/* This is my
First program &
This is my first file */
//This is my
// First program &
//This is my first file

 Link Section:

 The link section provides instructions to the compiler to link functions


from the system library.
 Library file include in a program with #include directive is considered as
a Link section.
 When we compile our program, it has to be link with .h extension base
file.
 These files are considered as library or header file.

Prepared by Mr. Pankaj M. Zalera 7


Programing In C [SMT. V.B. NANDOLA COMPUTER SCIECNE COLLEGE, BHACHA]

 Definition Section:

 It is firstly processed before void main()


 Example:

# include<stdio.h>
# define L 100;
void main()
{
int b,p;
clrscr();
printf(“\n Enter Breath”);
scanf(“%d”,&b);
p=2*( L + b);
printf(“\n Perameter Is : %d”,p);
getch();
}
 The definition section defines all symbolic constants.
 Definition is considered as pre-processing section because before
compiling main function processor compiles definition section first.
 With Definition section symbolic constant is created (L).
 Inside the main function when symbol comes, compiler replaces its
value.
 Global Declaration Section:-

 Life-line of Global Declaration Section variable is not restricted only in a


main function.
 But global variable can be utilized within any UDF (Sub-Program)
without declaring them.
 With Global Declaration user‟s coding is reduced.
 Global Declaration is also called Public Declaration.
 Some variable are used in more than one function. Such variables are
called Global variables.
 Main Function:-

 Every „C‟ program must have one main().


 User‟s problem must have write within main function.
 This section contains two parts, Declaration part and Execution part.
 The declaration part declares all the variable used in executable part.
These are at least one statement in the executable part.
 First declaration part considered within main function and this kind of
declaration called Local Declaration.
 The program execution being at the opening braces ({) and ends at
closing brace (}). The closing brace of main function section is the
logical end of the program.
 Sub-program Section:-
 To reduce the complexity of a program sub-program & UDF concept are
developed.

Prepared by Mr. Pankaj M. Zalera 8


Programing In C [SMT. V.B. NANDOLA COMPUTER SCIECNE COLLEGE, BHACHA]

 Program maintenance & debugging can be done very easily with


invention of UDF.
 We can create numbers of UDF within main function.
 UDF can be created within UDF.
Q. 8 Write a short note on „C‟ Tokens.
 In „C‟ program smallest individual units are known as „C‟ Tokens. „C‟ has
six types of tokens namely:
1) Keywords
2) Identifiers
3) Constants
4) Strings
5) Operators
6) Special symbols

1. Keywords:

 Every „C‟ word is classified as either a keyword or identifiers. All


keywords are pre-defined words with pre-defined meaning and serve as
basic blocks for program statements.
 The keywords can‟t be used as variable to the keyword, which not
allowed by the computer.
 The keywords are also called “Reserved words”. There are only 32
keywords available in „C‟.
 Following the list of some keywords are as given below:
auto double if static
break else int struct
case enum long switch
char extern near typedef
const float register union
continue far return unsigned
default for short void
do goto signed while
2. Identifiers:
 Identifier refers to the names of variables, functions and arrays.
 These are the user defined the names which consist of sequence of
letters and digits with a letter as a first character.
 Both uppercase and lowercase characters are permitted.

3. Constants:
 Constants in „C‟ refer to fixed values that do not change during the
execution of a program.
 „C‟ supports basically Integers constants, Real constants and character
constants.
4. Strings:-
 String is also considered as a part of character constants. A character
constant contains is either alphabet or digits or special symbols enclosed
within double inverted commas.
Prepared by Mr. Pankaj M. Zalera 9
Programing In C [SMT. V.B. NANDOLA COMPUTER SCIECNE COLLEGE, BHACHA]

5. Operators:-
 „C‟ supports a rich set of operators. An operator is a symbol that tells the
computer to perform certain mathematical and logical manipulations.
 There are eight types of operators in „C‟. They include:
A. Arithmetic
B. Relational
C. Logical
D. Assignment
E. Increment & Decrement
F. Conditional
G. Bitwise
H. Special

6. Special symbols:-
 There are some of the special symbols in computer. We can use these
symbols in programming „C‟.
 Ex.:
+ - * / { } ( ) [ ] ; : „ “ , . ? # etc.

Q. 9 What are different types of „C‟ instruction.


 There are basically five types of instruction in „C‟:
1) Type Declaration Instruction
2) Input/output Instruction
3) Arithmetic Instruction
4) Control Instruction
5) Conditional Instruction

1. Type Declaration Instruction


 This instruction is used for declaring type of variable. Any variable used
in the program must be declared before using it in any statement.
 e.g.:
int m1, m2, m3, mno;
float per, total;
char name[10];

2. Input/output Instruction
 These instructions are used for string and displaying value.
 e.g.:
scanf();
printf();
puts();
gets();

Prepared by Mr. Pankaj M. Zalera 10


Programing In C [SMT. V.B. NANDOLA COMPUTER SCIECNE COLLEGE, BHACHA]

3. Arithmetic Instruction
 To perform Addition, Subtraction, multiplication, Division this
instructions are used as operators.
 e.g.:
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulo Division
4. Conditional Instruction
 For checking condition of instruction on this instructions are used.
 e.g.:
if
if…..else
switch…..case
5. Control Instruction
 To control the sequence of execution of various statement in a „C‟
program by using control instruction.
 e.g.:
for()
while()
do…while()
Q. 10 Discuss the Hierarchy of Operations.
 The order or priority or the precedence in which the arithmetic
statements is called as the Hierarchy of operations. The hierarchy of
operations while evaluating any arithmetic instructions in „C‟ can be
narrated as follow:

Operator Operation Used for Associativity Precedence


() Function call
Left to Right First
[] Array expression
++ Increment
-- Decrement Right to Left Second
sizeof() Size of operand
* Multiplication
/ Division Left to Right Third
% Modulo division
+ Binary addition
Left to Right Fourth
- Binary Subtraction
 For Example:
I = 4/2*4+2-3/2
= 2*4+2-3/2
= 2*4+2-1
= 8+2-1
= 10-1
I = 9
Prepared by Mr. Pankaj M. Zalera 11
Programing In C [SMT. V.B. NANDOLA COMPUTER SCIECNE COLLEGE, BHACHA]

Q. 11 Explain the advantages and Disadvantages of „C‟ language.

Advantages:-
1) „C‟ is a powerful & flexible language.
2) „C‟ is a considered as a portable language. Portable means „C‟ program
can be compiled on any platform (O.S. [DOS/WINDOWS]).
3) Maximum data type we can use in „C‟ language.
4) For the mathematical and string type operation, different library files are
available.
5) For creation of graphics library file is also available <graphics.h>.
6) We can create data file in „C‟ language.
7) For the execution of program very fast pointer type facility is available.
8) We can define structure and union in „C‟ language.
9) Maximum data types are available in „C‟ language.

Disadvantages:-
1) Perform, reading & understanding is difficult.
2) Whenever error create in program modification in the program is
difficult.
3) Usage of pointer is also difficult.

Prepared by Mr. Pankaj M. Zalera 12

You might also like