SlideShare una empresa de Scribd logo
1 de 50
20GE101- STRUCTURED PROGRAMMING
USING C
Unit II
Basics of C Programming
Overview of C – C Character Set – Identifiers and Keywords –
Declaration – Data Types – Type Qualifiers and Type Modifiers –
Variables and Constants – Structure of a C Program – Executing a C
Program – Operators and Expressions – Decision-Making and
Looping Statements.
Introduction to C programming
Types of Language:
Low level Language (or) Machine Language.
• A machine language or an assembly language. Low-level
languages are closer to the hardware.
• Low-level languages can be converted to machine code without
using a compiler or interpreter, and the resulting code runs
directly on the processor.
High Level Language
• Normal English, human understandable language, machine
independent, C++, java, BASIC, COBOL, FORTRAN, etc…
Middle Level Language
• C Language is also called as Middle level Language because ‘C’
stands in between Low level Language (nor) high level
language.
• It performs task of low level languages as well as high level
language.
• We can write program for operating, application programs,
Assembly language programs in ‘C’ Languages.
• UNIX operating system is written in ‘C’ Language.
History of C-Language:
• C is a structured, procedural programming language, and most
powerful Language.
• C was developed by Dennis Ritchie at AT & T Bell laboratory in
1972.
• It is an upgraded version of two earlier languages, called BCPL
and B, which were also developed at Bell laboratories.
History of C-Language:
Sl. No Language Year Founders
1. ALGOL 1960 International Committee
2. BCPL 1967 Martin Richards
3. B 1970 Ken Thompson
4. C 1972 Dennis Ritchie
5. K & R C 1978 Kernighan and Ritchie
6. ANSI C 1989 ANSI Committee
7. ANSI / ISO C 1990 ISO Committee
History of C-Language:
• All modern computer languages are started through the ALGOL
(ALGOrithmic Language) language in 1960.
• After the COBOL was being used for commercial applications.
• FORTAN was developed for scientific applications.
• A committee was formed to develop a new language called
Combined Programming Language (CPL) at Cambridge
University.
• Basic CPL was derived by BCPL.
• BCPL was developed by Martin Richards at Cambridge
University by 1967.
• At the same time a language called ‘B’ was developed by Ken
Thomson at AT & T’s Bell labs in 1970.
History of C-Language:
• B language does not have Data type and it does not provide the
structure to overcome this Ritchie introduced C language.
• Then C language is developed by Dennis Ritchie in 1972 with
some additional features of BCPL and B which is very simple.
Using C language UNIX operating system is made.
• ANSI C American National Standard Institute has began to work
on a standardized definition of the ‘C’ language that makes it
still powerful.
Features and Applications of ‘C’ Languages:
1. C is a general purpose, structured programming language.
2. C is a powerful, efficient, compact & flexible.
3. C is highly portable. It can run in different operating systems
environment.
4. C is robust language. It has built in functions and operators can
be used to write any complex program.
5. C is well suited for writing system software as well as
application software.
6. C is middle level language. It supports low level & high level
language.
7. C language allows reference to memory allocation with the help
of the pointers.
8. C language allows dynamic memory allocation. C programs are
fast and efficient.
C Character Set
• A character set defines the valid characters that can be used in
a source program or interpreted when a program is running.
• The set of characters that can be used to write a source
program is called a source character set.
• The set of characters available when the program is being
executed is called an execution character set.
• The basic source character set of C language includes:
1. Letters:
 Uppercase letters: A, B, C,….., Z
 Lowercase letters: a, b, c,……, z
2. Digits: 0, 1, 2, 3……, 9
3. Special characters: ,.;;!”^#$%@&*()[]{}<>|/_~ etc
C Character Set
4. White space characters:
a. Blank space character
b. Horizontal tab space character
c. Carriage return
d. New line character
e. Form feed character
Identifiers and Keywords
Identifier
• An Identifier refers to an object.
• It can be a variable name, a label name, a function name, a
typedef name, a macro name or a macro parameter, a tag or a
member of a structure, a union or an enumeration.
Identifier
• The syntactic rules to write an identifier name in C are as
follows;
• Identifier name in C can have letters, digits or underscores.
• The first character of an identifier name must be a letter (Either
Uppercase or lowercase) or an underscore. The first character
of an identifier name cannot be a digit.
• No special character (except an underscore), blank space and
comma can be used in an identifier name.
• Keywords or reserved words cannot form a valid identifier
name.
• The maximum number of characters allowed in an identifier
name is compiler dependent, but the limit imposed by all the
compilers provides enough flexibility to create meaningful
identifier name.
Identifier
• The following identifier names are valid in C:
 Student_Name
 StudentName
 Student_name
 Student1
 _Student
• The following identifier names are not valid in C;
 Student Name (due to blank space)
 Name&Rollno (due to special character &)
 1st_student (First character begin a digit)
 for (for being a keyword)
Keywords
• Keywords are the reserved words that has a particular meaning
in the programming language.
• The meaning of a keyword is predefined. Each keywords has
fixed meaning and that cannot be changed by user.
• A keyword cannot be used as an identifier name in C language.
C has 32 keywords. They always written in lowercase. The C
keywords are,
Auto double int struct
break else long switch
case enum register typedef
char extern return union
const float short unsigned
continue for signed void
default goto sizeof volatile
do if static while
Variables and Constant
• A variable is a identifier that is used to represent some specified
type of information.
• A variable is a area of storage that can hold a single value (numeric
or character).
• A variable specifies a data type and contains a list of one or more
variables of that type.
Variables:
Variables
Rules for naming the variable:
1. The variable name can be any combination of 1 to 8 alphabets,
digits or underscore.
2. The first character must be an alphabet letters, some system
permits underscore ( _ ) as first character .
3. The length of the variable cannot exceed up to 8 characters long,
and ANSI C compilers recognize up to 31 character long.
4. No commas or blank spaces are allowed within a variable name.
5. Variable name should not be a C- keyword.
6. No special symbol, an underscore can be used in a variable name.
Variables
Declaration of Variables:
• After designing suitable variable name, we must declare them in
to a program.
• This declaration tells the compiler what the variable and type of
the data that the variable will hold.
• Here, a,b,c,d is list of variable names it is a integer type variable,
i.e., it can hold integer value.
• Add, result is a floating point variable. Which holds an decimal
numbers.
Syntax:
data type variable name 1, …variable name n;
Example:
int a,b,c,d;
float add, result;
char name;
Variables
Initializing variables:
• Initializing the variable can be done using the assignment
operator(=).
• The variable can be initialized when the value is declared itself.
Syntax:
Data_type variable_name=constant
value;
Example:
int i=45;
float var1=28.67;
char c=’t’;
Variables
Global variable:
Global variables are declared above the main() function in the
following way.
Example:
#include<stdio.h>
short number, sum;
int bignumber, bigsum; // Global variable declaration;
void main()
{
//methods and execution statement declaration;
}
Variables
Variables has spitted into two categories.
• Local variable.
• Global variable.
• Local Variable: The variable declared within the function.
(i.e., with in the open and closed curly brace ‘{}’)
Example:
#include<stdio.h>
int main()
{ int a=10, b=20,c; // a, b and c are variables with constant
values 10,20.
//here, a,b,c is a local variable.
c=a+b;
printf(“the result is %d”,c);
}
OUTPUT:
30.
Constants
• The constants refer to fixed values that the program may not alter
during its execution. These fixed values are also called literals.
• A constant is an entity whose value remains the same throughout
the execution of a program.
• Literal Constants
• Qualified Constants
• Symbolic Constants
Constants
Literal Constants:
• Literal constants or just literal denotes a fixed values, which may
be an integer, floating point number, character or a string.
• Literal constants are of the following types,
• Integer literal constant
• Floating point literal constant
• Character literal constant
• String literal constant
Constants
Integer Literal Constants:
• Integer Literal Constants are integer values like -1, 2,8 etc.
RULES:
 An Integer Literal Constants must have at least one digit.
 It should not have any decimal point.
 Can be positive or negative. If no sign precedes an integer literal
constants, then it is assumed to be positive.
 No special characters (Even Underscore) and blank spaces are
allowed.
Constants
Floating point Literal Constants:
• Floating point Literal Constants are values like -23.1, 12.8 etc.
RULES:
 A fractional Floating point Literal Constants must have at least
one digit.
 It should have any decimal point.
 Can be positive or negative. If no sign precedes an integer literal
constants, then it is assumed to be positive.
 No special characters (Even Underscore) and blank spaces are
allowed.
Constants
Character Literal Constants:
• A character literal constants can have one or at most two
characters enclosed with single quotes. eg) ‘A’, ‘a’, ‘n’ etc.
• Character literal constants are classified as,
 Printable character literal constants
 Non-printable character literal constants
Printable character literal constants:
• All characters of source character set except quotation mark,
backslash and new line character when enclosed within single
quotes form a printable character literal constant.
• Example: ‘A’, ‘#’, ‘6’
Constants
Non-Printable character literal constants:
• Non-Printable character literal constants are represented with the
help of escape sequences.
• An escape sequence consist of backward slash (i.e. ) followed by
a character and both enclosed within single quotes.
Constants
Non-Printable character literal constants:
Constants
String literal constant:
• A string literal constant consists of a sequence of character
enclosed with in double quotes.
• Each string literal constant is implicitly terminated by a null
character (i.e. ‘0’)
Constants
Qualified Constants:
• Qualified constants are created by using const qualifier.
• The following statement creates a qualifier character constant
named a;
const char a=‘A’;
Constants
Symbolic constants:
• Symbolic constants are created with the help of the define
preprocessor directive.
• For example,
#define pi 3.14
Here pi is a symbolic constant with values 3.14
Structure Of C-Programming:
• C language is a programming language and it is also a
structured programming language was developed by Dennis
Ritchie in 1972.
• Every C program contains a number of building blocks. These
blocks are written in a correct order and procedure.
Structure Of C-Programming:
Structure Of C-Programming:
1.Documentation Block:
• Documentation block contains the information about the
program. Like program name, author name, date of
development and program details.
• This block should be written with in Multi lines command.
Because the compiler does not compile the lines present in the
command lines.
• It is optional one in C structure.
• Command Lines has two types.
• Single line command- It should be written with in “//”(Double
slash)
• Multi line command- multi line command consist of two or
more lines. Should start with “/*” and end with “*/”.
Structure Of C-Programming:
2.Preprocessor directive block:
• It provides preprocessor statement which direct the compiler to
link functions from the system library.
• Header files is necessary. include in this block. With out this
header files a program does not link with the system library.
Example:
#include<stdio.h>
Here, #  Preprocessor directive.
<stdio.h>  header files end with .h extension.
Structure Of C-Programming:
3.Definition Block:
• Definition block is used to declare the constant values as
globally.
Syntax:
#define constant_name constant_value
Example:
#define π=3.14
4.Global Variable Declaration Block:
• It contains variable declarations which can be accessed
anywhere within the program.
Structure Of C-Programming:
5.Main Function:
• C program execution is starts from main function. Every c
program must contain C program.
• Main section is divided into two portions.
 Declaration part
 Execution part
• Declaration part is used to declare any variable in main block of
the program.
• Execution part contains set of statement which is used to take
the input from the user process it, and displaying the result.
These statements are pre defined type.
• Execution of the program begins and ends with in the open and
close ‘{}’ curly brace.
Structure Of C-Programming:
6. Sub program block:
• Sub program section or user defined section contains user
defined function which are called by main functions.
• Each user defined functions contains the function name,
argument and return values.
Executing a C Program
Compilation and Linking Processes
Executing a C program involves a series of steps, there are,
• Creating a program
• Compiling the program
• Linking the program with functions that are needed from the C
library.
• Executing the program
Executing a C Program
Executing a C Program
Preprocessing:
• The preprocessor changes the program according to the directives
mentioned (that starts with # sign). The C preprocessor takes the
program and deals with the # include directives and the resulting
program.
Compilation:
• It translates the program into a low level assembly level code. The
compiler takes the preprocessed file and generates an object file
containing Assembly level code.
• Assembly - Using a Assembler program to convert assembly source code
to object code.
Linking:
• The creation of a single executable file from multiple object files. The file
created, after linking is ready to be loaded into memory and executed by
the system.
• Using a Linker program to convert object code to executable code.
Multiple units of object codes are linked to together in this step.
Executing a C
Program
Process of
Compilation and
linking in C program:
DATA TYPES IN C
• Data type is the type of data, that are going to access within the
program.
• C data types are defined as the data storage format that a
variable can store a data to perform a specific operation.
• Data types are used to define a variable before to use in a
program.
• Size of variable, constant and array are determined by data
types.
• A data type is used to
 Identify the type of a variable when the variable is declared
 Identify the type of the return value of a function
 Identify the type of a parameter expected by a function.
DATA TYPES IN C
Void is
valueless 
DATA TYPES IN C
1.Primitive Data Type:
 The primitive data types in c language are the inbuilt data types
provided by the C language itself. Thus, all c compilers provide
support for these data types.
Integer (int):
 Integer data type is used to declare a variable that can store
numbers without a decimal.
 The keyword used to declare a variable of integer type is “int”.
 Syntax:
int variable_name;
DATA TYPES IN C
Float point (float):
• Float data type declares a variable that can store numbers
containing a decimal number.
• Syntax:
float variable_name;
Character (char):
• Character data type declares a variable that can store a
character constant. Thus, the variables declared as char data
type can only store one single character.
• Syntax:
char variable_name;
DATA TYPES IN C
Double Data Type (double):
• Double data type also declares variable that can store floating
point numbers but gives precision double than that provided by
float data type.
• Thus, double data type are also referred to as double precision
data type.
• Syntax:
double variable_name;
Valueless (void):
• void data type does not create any variable but returns an
empty set of values. Thus, we can say that it stores null.
• Syntax:
void variable_name;
DATA TYPES IN C
DATA TYPES IN C
DATA TYPES IN C
2.Derived Data Types
• Derived Data Type are a derivative of primitive data types
known as arrays, pointer and function.
• Array – A finite sequence (or table) of variables of the same data type
• String – An array of character variables
• Structure – A collection of related variables of the same and/or
different data types. The structure is called a record and the variables
in the record are called members or fields.
3.User Defined Data Types:
• User defined data types are those data types which are defined
by the user/programmer himself.
• Structure, union and enum are user defined data types.
• These are also referred to as composite data types.
Basics of C Programming

Más contenido relacionado

La actualidad más candente

La actualidad más candente (19)

C LANGUAGE NOTES
C LANGUAGE NOTESC LANGUAGE NOTES
C LANGUAGE NOTES
 
C presentation book
C presentation bookC presentation book
C presentation book
 
C programming slide day 01 uploadd by md abdullah al shakil
C programming slide day 01 uploadd by md abdullah al shakilC programming slide day 01 uploadd by md abdullah al shakil
C programming slide day 01 uploadd by md abdullah al shakil
 
A brief introduction to C Language
A brief introduction to C LanguageA brief introduction to C Language
A brief introduction to C Language
 
Features of c language 1
Features of c language 1Features of c language 1
Features of c language 1
 
C notes by m v b reddy(gitam)imp notes all units notes 5 unit order
C notes by m v b  reddy(gitam)imp  notes  all units notes  5 unit orderC notes by m v b  reddy(gitam)imp  notes  all units notes  5 unit order
C notes by m v b reddy(gitam)imp notes all units notes 5 unit order
 
Introduction to C programming
Introduction to C programmingIntroduction to C programming
Introduction to C programming
 
C notes
C notesC notes
C notes
 
C Language
C LanguageC Language
C Language
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
 
Programming in c
Programming in cProgramming in c
Programming in c
 
C Language
C LanguageC Language
C Language
 
Features of c
Features of cFeatures of c
Features of c
 
Programming in c
Programming in cProgramming in c
Programming in c
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
Introduction to C Programming - I
Introduction to C Programming - I Introduction to C Programming - I
Introduction to C Programming - I
 
C programming part1
C programming part1C programming part1
C programming part1
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
 
C programming language Reference Note
C programming language Reference NoteC programming language Reference Note
C programming language Reference Note
 

Similar a Basics of C Programming

Similar a Basics of C Programming (20)

C PROGRAMMING p-1.pdf
C PROGRAMMING p-1.pdfC PROGRAMMING p-1.pdf
C PROGRAMMING p-1.pdf
 
CSE 1201: Structured Programming Language
CSE 1201: Structured Programming LanguageCSE 1201: Structured Programming Language
CSE 1201: Structured Programming Language
 
C language unit-1
C language unit-1C language unit-1
C language unit-1
 
C LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDY
C LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDYC LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDY
C LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDY
 
C PROGRAMMING LANGUAGE.pptx
 C PROGRAMMING LANGUAGE.pptx C PROGRAMMING LANGUAGE.pptx
C PROGRAMMING LANGUAGE.pptx
 
Unit ii
Unit   iiUnit   ii
Unit ii
 
Basics of C.ppt
Basics of C.pptBasics of C.ppt
Basics of C.ppt
 
Basics of C
Basics of CBasics of C
Basics of C
 
Basics of C.ppt
Basics of C.pptBasics of C.ppt
Basics of C.ppt
 
Basics of C.ppt
Basics of C.pptBasics of C.ppt
Basics of C.ppt
 
Funa-C.ppt
Funa-C.pptFuna-C.ppt
Funa-C.ppt
 
Basics of C.ppt
Basics of C.pptBasics of C.ppt
Basics of C.ppt
 
Basics of C (1).ppt
Basics of C (1).pptBasics of C (1).ppt
Basics of C (1).ppt
 
Basics of C.ppt
Basics of C.pptBasics of C.ppt
Basics of C.ppt
 
C programming basic pdf.ppt
C programming basic pdf.pptC programming basic pdf.ppt
C programming basic pdf.ppt
 
Basics of C.ppt
Basics of C.pptBasics of C.ppt
Basics of C.ppt
 
Basics of C--C Basics------------------.ppt
Basics of C--C Basics------------------.pptBasics of C--C Basics------------------.ppt
Basics of C--C Basics------------------.ppt
 
Basics of C.ppt
Basics of C.pptBasics of C.ppt
Basics of C.ppt
 
Basics of C.ppt
Basics of C.pptBasics of C.ppt
Basics of C.ppt
 
Basics of C.ppt
Basics of C.pptBasics of C.ppt
Basics of C.ppt
 

Más de SIMONTHOMAS S

Cs8092 computer graphics and multimedia unit 5
Cs8092 computer graphics and multimedia unit 5Cs8092 computer graphics and multimedia unit 5
Cs8092 computer graphics and multimedia unit 5SIMONTHOMAS S
 
Cs8092 computer graphics and multimedia unit 4
Cs8092 computer graphics and multimedia unit 4Cs8092 computer graphics and multimedia unit 4
Cs8092 computer graphics and multimedia unit 4SIMONTHOMAS S
 
Cs8092 computer graphics and multimedia unit 3
Cs8092 computer graphics and multimedia unit 3Cs8092 computer graphics and multimedia unit 3
Cs8092 computer graphics and multimedia unit 3SIMONTHOMAS S
 
Cs8092 computer graphics and multimedia unit 2
Cs8092 computer graphics and multimedia unit 2Cs8092 computer graphics and multimedia unit 2
Cs8092 computer graphics and multimedia unit 2SIMONTHOMAS S
 
Cs8092 computer graphics and multimedia unit 1
Cs8092 computer graphics and multimedia unit 1Cs8092 computer graphics and multimedia unit 1
Cs8092 computer graphics and multimedia unit 1SIMONTHOMAS S
 
IT6701-Information Management Unit 5
IT6701-Information Management Unit 5IT6701-Information Management Unit 5
IT6701-Information Management Unit 5SIMONTHOMAS S
 
IT6701-Information Management Unit 4
IT6701-Information Management Unit 4IT6701-Information Management Unit 4
IT6701-Information Management Unit 4SIMONTHOMAS S
 
IT6701-Information Management Unit 3
IT6701-Information Management Unit 3IT6701-Information Management Unit 3
IT6701-Information Management Unit 3SIMONTHOMAS S
 
IT6701-Information Management Unit 2
IT6701-Information Management Unit 2IT6701-Information Management Unit 2
IT6701-Information Management Unit 2SIMONTHOMAS S
 
IT6701-Information Management Unit 1
IT6701-Information Management Unit 1IT6701-Information Management Unit 1
IT6701-Information Management Unit 1SIMONTHOMAS S
 
CS8391-Data Structures Unit 5
CS8391-Data Structures Unit 5CS8391-Data Structures Unit 5
CS8391-Data Structures Unit 5SIMONTHOMAS S
 
CS8391-Data Structures Unit 4
CS8391-Data Structures Unit 4CS8391-Data Structures Unit 4
CS8391-Data Structures Unit 4SIMONTHOMAS S
 
CS8391-Data Structures Unit 3
CS8391-Data Structures Unit 3CS8391-Data Structures Unit 3
CS8391-Data Structures Unit 3SIMONTHOMAS S
 
CS8391-Data Structures Unit 2
CS8391-Data Structures Unit 2CS8391-Data Structures Unit 2
CS8391-Data Structures Unit 2SIMONTHOMAS S
 
CS8391-Data Structures Unit 1
CS8391-Data Structures Unit 1CS8391-Data Structures Unit 1
CS8391-Data Structures Unit 1SIMONTHOMAS S
 

Más de SIMONTHOMAS S (20)

Cs8092 computer graphics and multimedia unit 5
Cs8092 computer graphics and multimedia unit 5Cs8092 computer graphics and multimedia unit 5
Cs8092 computer graphics and multimedia unit 5
 
Cs8092 computer graphics and multimedia unit 4
Cs8092 computer graphics and multimedia unit 4Cs8092 computer graphics and multimedia unit 4
Cs8092 computer graphics and multimedia unit 4
 
Cs8092 computer graphics and multimedia unit 3
Cs8092 computer graphics and multimedia unit 3Cs8092 computer graphics and multimedia unit 3
Cs8092 computer graphics and multimedia unit 3
 
Cs8092 computer graphics and multimedia unit 2
Cs8092 computer graphics and multimedia unit 2Cs8092 computer graphics and multimedia unit 2
Cs8092 computer graphics and multimedia unit 2
 
Cs8092 computer graphics and multimedia unit 1
Cs8092 computer graphics and multimedia unit 1Cs8092 computer graphics and multimedia unit 1
Cs8092 computer graphics and multimedia unit 1
 
Mg6088 spm unit-5
Mg6088 spm unit-5Mg6088 spm unit-5
Mg6088 spm unit-5
 
Mg6088 spm unit-4
Mg6088 spm unit-4Mg6088 spm unit-4
Mg6088 spm unit-4
 
Mg6088 spm unit-3
Mg6088 spm unit-3Mg6088 spm unit-3
Mg6088 spm unit-3
 
Mg6088 spm unit-2
Mg6088 spm unit-2Mg6088 spm unit-2
Mg6088 spm unit-2
 
Mg6088 spm unit-1
Mg6088 spm unit-1Mg6088 spm unit-1
Mg6088 spm unit-1
 
IT6701-Information Management Unit 5
IT6701-Information Management Unit 5IT6701-Information Management Unit 5
IT6701-Information Management Unit 5
 
IT6701-Information Management Unit 4
IT6701-Information Management Unit 4IT6701-Information Management Unit 4
IT6701-Information Management Unit 4
 
IT6701-Information Management Unit 3
IT6701-Information Management Unit 3IT6701-Information Management Unit 3
IT6701-Information Management Unit 3
 
IT6701-Information Management Unit 2
IT6701-Information Management Unit 2IT6701-Information Management Unit 2
IT6701-Information Management Unit 2
 
IT6701-Information Management Unit 1
IT6701-Information Management Unit 1IT6701-Information Management Unit 1
IT6701-Information Management Unit 1
 
CS8391-Data Structures Unit 5
CS8391-Data Structures Unit 5CS8391-Data Structures Unit 5
CS8391-Data Structures Unit 5
 
CS8391-Data Structures Unit 4
CS8391-Data Structures Unit 4CS8391-Data Structures Unit 4
CS8391-Data Structures Unit 4
 
CS8391-Data Structures Unit 3
CS8391-Data Structures Unit 3CS8391-Data Structures Unit 3
CS8391-Data Structures Unit 3
 
CS8391-Data Structures Unit 2
CS8391-Data Structures Unit 2CS8391-Data Structures Unit 2
CS8391-Data Structures Unit 2
 
CS8391-Data Structures Unit 1
CS8391-Data Structures Unit 1CS8391-Data Structures Unit 1
CS8391-Data Structures Unit 1
 

Último

Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 
Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...121011101441
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...asadnawaz62
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfAsst.prof M.Gokilavani
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfme23b1001
 
US Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of ActionUS Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of ActionMebane Rash
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxk795866
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxKartikeyaDwivedi3
 
8251 universal synchronous asynchronous receiver transmitter
8251 universal synchronous asynchronous receiver transmitter8251 universal synchronous asynchronous receiver transmitter
8251 universal synchronous asynchronous receiver transmitterShivangiSharma879191
 
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfgUnit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfgsaravananr517913
 
Transport layer issues and challenges - Guide
Transport layer issues and challenges - GuideTransport layer issues and challenges - Guide
Transport layer issues and challenges - GuideGOPINATHS437943
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)dollysharma2066
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvLewisJB
 
computer application and construction management
computer application and construction managementcomputer application and construction management
computer application and construction managementMariconPadriquez1
 

Último (20)

POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdf
 
US Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of ActionUS Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of Action
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptx
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptx
 
8251 universal synchronous asynchronous receiver transmitter
8251 universal synchronous asynchronous receiver transmitter8251 universal synchronous asynchronous receiver transmitter
8251 universal synchronous asynchronous receiver transmitter
 
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfgUnit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
 
Transport layer issues and challenges - Guide
Transport layer issues and challenges - GuideTransport layer issues and challenges - Guide
Transport layer issues and challenges - Guide
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvv
 
computer application and construction management
computer application and construction managementcomputer application and construction management
computer application and construction management
 

Basics of C Programming

  • 1. 20GE101- STRUCTURED PROGRAMMING USING C Unit II Basics of C Programming Overview of C – C Character Set – Identifiers and Keywords – Declaration – Data Types – Type Qualifiers and Type Modifiers – Variables and Constants – Structure of a C Program – Executing a C Program – Operators and Expressions – Decision-Making and Looping Statements.
  • 2. Introduction to C programming Types of Language: Low level Language (or) Machine Language. • A machine language or an assembly language. Low-level languages are closer to the hardware. • Low-level languages can be converted to machine code without using a compiler or interpreter, and the resulting code runs directly on the processor. High Level Language • Normal English, human understandable language, machine independent, C++, java, BASIC, COBOL, FORTRAN, etc…
  • 3. Middle Level Language • C Language is also called as Middle level Language because ‘C’ stands in between Low level Language (nor) high level language. • It performs task of low level languages as well as high level language. • We can write program for operating, application programs, Assembly language programs in ‘C’ Languages. • UNIX operating system is written in ‘C’ Language.
  • 4. History of C-Language: • C is a structured, procedural programming language, and most powerful Language. • C was developed by Dennis Ritchie at AT & T Bell laboratory in 1972. • It is an upgraded version of two earlier languages, called BCPL and B, which were also developed at Bell laboratories.
  • 5. History of C-Language: Sl. No Language Year Founders 1. ALGOL 1960 International Committee 2. BCPL 1967 Martin Richards 3. B 1970 Ken Thompson 4. C 1972 Dennis Ritchie 5. K & R C 1978 Kernighan and Ritchie 6. ANSI C 1989 ANSI Committee 7. ANSI / ISO C 1990 ISO Committee
  • 6. History of C-Language: • All modern computer languages are started through the ALGOL (ALGOrithmic Language) language in 1960. • After the COBOL was being used for commercial applications. • FORTAN was developed for scientific applications. • A committee was formed to develop a new language called Combined Programming Language (CPL) at Cambridge University. • Basic CPL was derived by BCPL. • BCPL was developed by Martin Richards at Cambridge University by 1967. • At the same time a language called ‘B’ was developed by Ken Thomson at AT & T’s Bell labs in 1970.
  • 7. History of C-Language: • B language does not have Data type and it does not provide the structure to overcome this Ritchie introduced C language. • Then C language is developed by Dennis Ritchie in 1972 with some additional features of BCPL and B which is very simple. Using C language UNIX operating system is made. • ANSI C American National Standard Institute has began to work on a standardized definition of the ‘C’ language that makes it still powerful.
  • 8. Features and Applications of ‘C’ Languages: 1. C is a general purpose, structured programming language. 2. C is a powerful, efficient, compact & flexible. 3. C is highly portable. It can run in different operating systems environment. 4. C is robust language. It has built in functions and operators can be used to write any complex program. 5. C is well suited for writing system software as well as application software. 6. C is middle level language. It supports low level & high level language. 7. C language allows reference to memory allocation with the help of the pointers. 8. C language allows dynamic memory allocation. C programs are fast and efficient.
  • 9. C Character Set • A character set defines the valid characters that can be used in a source program or interpreted when a program is running. • The set of characters that can be used to write a source program is called a source character set. • The set of characters available when the program is being executed is called an execution character set. • The basic source character set of C language includes: 1. Letters:  Uppercase letters: A, B, C,….., Z  Lowercase letters: a, b, c,……, z 2. Digits: 0, 1, 2, 3……, 9 3. Special characters: ,.;;!”^#$%@&*()[]{}<>|/_~ etc
  • 10. C Character Set 4. White space characters: a. Blank space character b. Horizontal tab space character c. Carriage return d. New line character e. Form feed character
  • 11. Identifiers and Keywords Identifier • An Identifier refers to an object. • It can be a variable name, a label name, a function name, a typedef name, a macro name or a macro parameter, a tag or a member of a structure, a union or an enumeration.
  • 12. Identifier • The syntactic rules to write an identifier name in C are as follows; • Identifier name in C can have letters, digits or underscores. • The first character of an identifier name must be a letter (Either Uppercase or lowercase) or an underscore. The first character of an identifier name cannot be a digit. • No special character (except an underscore), blank space and comma can be used in an identifier name. • Keywords or reserved words cannot form a valid identifier name. • The maximum number of characters allowed in an identifier name is compiler dependent, but the limit imposed by all the compilers provides enough flexibility to create meaningful identifier name.
  • 13. Identifier • The following identifier names are valid in C:  Student_Name  StudentName  Student_name  Student1  _Student • The following identifier names are not valid in C;  Student Name (due to blank space)  Name&Rollno (due to special character &)  1st_student (First character begin a digit)  for (for being a keyword)
  • 14. Keywords • Keywords are the reserved words that has a particular meaning in the programming language. • The meaning of a keyword is predefined. Each keywords has fixed meaning and that cannot be changed by user. • A keyword cannot be used as an identifier name in C language. C has 32 keywords. They always written in lowercase. The C keywords are, Auto double int struct break else long switch case enum register typedef char extern return union const float short unsigned continue for signed void default goto sizeof volatile do if static while
  • 15. Variables and Constant • A variable is a identifier that is used to represent some specified type of information. • A variable is a area of storage that can hold a single value (numeric or character). • A variable specifies a data type and contains a list of one or more variables of that type. Variables:
  • 16. Variables Rules for naming the variable: 1. The variable name can be any combination of 1 to 8 alphabets, digits or underscore. 2. The first character must be an alphabet letters, some system permits underscore ( _ ) as first character . 3. The length of the variable cannot exceed up to 8 characters long, and ANSI C compilers recognize up to 31 character long. 4. No commas or blank spaces are allowed within a variable name. 5. Variable name should not be a C- keyword. 6. No special symbol, an underscore can be used in a variable name.
  • 17. Variables Declaration of Variables: • After designing suitable variable name, we must declare them in to a program. • This declaration tells the compiler what the variable and type of the data that the variable will hold. • Here, a,b,c,d is list of variable names it is a integer type variable, i.e., it can hold integer value. • Add, result is a floating point variable. Which holds an decimal numbers. Syntax: data type variable name 1, …variable name n; Example: int a,b,c,d; float add, result; char name;
  • 18. Variables Initializing variables: • Initializing the variable can be done using the assignment operator(=). • The variable can be initialized when the value is declared itself. Syntax: Data_type variable_name=constant value; Example: int i=45; float var1=28.67; char c=’t’;
  • 19. Variables Global variable: Global variables are declared above the main() function in the following way. Example: #include<stdio.h> short number, sum; int bignumber, bigsum; // Global variable declaration; void main() { //methods and execution statement declaration; }
  • 20. Variables Variables has spitted into two categories. • Local variable. • Global variable. • Local Variable: The variable declared within the function. (i.e., with in the open and closed curly brace ‘{}’) Example: #include<stdio.h> int main() { int a=10, b=20,c; // a, b and c are variables with constant values 10,20. //here, a,b,c is a local variable. c=a+b; printf(“the result is %d”,c); } OUTPUT: 30.
  • 21. Constants • The constants refer to fixed values that the program may not alter during its execution. These fixed values are also called literals. • A constant is an entity whose value remains the same throughout the execution of a program. • Literal Constants • Qualified Constants • Symbolic Constants
  • 22. Constants Literal Constants: • Literal constants or just literal denotes a fixed values, which may be an integer, floating point number, character or a string. • Literal constants are of the following types, • Integer literal constant • Floating point literal constant • Character literal constant • String literal constant
  • 23. Constants Integer Literal Constants: • Integer Literal Constants are integer values like -1, 2,8 etc. RULES:  An Integer Literal Constants must have at least one digit.  It should not have any decimal point.  Can be positive or negative. If no sign precedes an integer literal constants, then it is assumed to be positive.  No special characters (Even Underscore) and blank spaces are allowed.
  • 24. Constants Floating point Literal Constants: • Floating point Literal Constants are values like -23.1, 12.8 etc. RULES:  A fractional Floating point Literal Constants must have at least one digit.  It should have any decimal point.  Can be positive or negative. If no sign precedes an integer literal constants, then it is assumed to be positive.  No special characters (Even Underscore) and blank spaces are allowed.
  • 25. Constants Character Literal Constants: • A character literal constants can have one or at most two characters enclosed with single quotes. eg) ‘A’, ‘a’, ‘n’ etc. • Character literal constants are classified as,  Printable character literal constants  Non-printable character literal constants Printable character literal constants: • All characters of source character set except quotation mark, backslash and new line character when enclosed within single quotes form a printable character literal constant. • Example: ‘A’, ‘#’, ‘6’
  • 26. Constants Non-Printable character literal constants: • Non-Printable character literal constants are represented with the help of escape sequences. • An escape sequence consist of backward slash (i.e. ) followed by a character and both enclosed within single quotes.
  • 28. Constants String literal constant: • A string literal constant consists of a sequence of character enclosed with in double quotes. • Each string literal constant is implicitly terminated by a null character (i.e. ‘0’)
  • 29. Constants Qualified Constants: • Qualified constants are created by using const qualifier. • The following statement creates a qualifier character constant named a; const char a=‘A’;
  • 30. Constants Symbolic constants: • Symbolic constants are created with the help of the define preprocessor directive. • For example, #define pi 3.14 Here pi is a symbolic constant with values 3.14
  • 31. Structure Of C-Programming: • C language is a programming language and it is also a structured programming language was developed by Dennis Ritchie in 1972. • Every C program contains a number of building blocks. These blocks are written in a correct order and procedure.
  • 33. Structure Of C-Programming: 1.Documentation Block: • Documentation block contains the information about the program. Like program name, author name, date of development and program details. • This block should be written with in Multi lines command. Because the compiler does not compile the lines present in the command lines. • It is optional one in C structure. • Command Lines has two types. • Single line command- It should be written with in “//”(Double slash) • Multi line command- multi line command consist of two or more lines. Should start with “/*” and end with “*/”.
  • 34. Structure Of C-Programming: 2.Preprocessor directive block: • It provides preprocessor statement which direct the compiler to link functions from the system library. • Header files is necessary. include in this block. With out this header files a program does not link with the system library. Example: #include<stdio.h> Here, #  Preprocessor directive. <stdio.h>  header files end with .h extension.
  • 35. Structure Of C-Programming: 3.Definition Block: • Definition block is used to declare the constant values as globally. Syntax: #define constant_name constant_value Example: #define π=3.14 4.Global Variable Declaration Block: • It contains variable declarations which can be accessed anywhere within the program.
  • 36. Structure Of C-Programming: 5.Main Function: • C program execution is starts from main function. Every c program must contain C program. • Main section is divided into two portions.  Declaration part  Execution part • Declaration part is used to declare any variable in main block of the program. • Execution part contains set of statement which is used to take the input from the user process it, and displaying the result. These statements are pre defined type. • Execution of the program begins and ends with in the open and close ‘{}’ curly brace.
  • 37. Structure Of C-Programming: 6. Sub program block: • Sub program section or user defined section contains user defined function which are called by main functions. • Each user defined functions contains the function name, argument and return values.
  • 38. Executing a C Program Compilation and Linking Processes Executing a C program involves a series of steps, there are, • Creating a program • Compiling the program • Linking the program with functions that are needed from the C library. • Executing the program
  • 39. Executing a C Program
  • 40. Executing a C Program Preprocessing: • The preprocessor changes the program according to the directives mentioned (that starts with # sign). The C preprocessor takes the program and deals with the # include directives and the resulting program. Compilation: • It translates the program into a low level assembly level code. The compiler takes the preprocessed file and generates an object file containing Assembly level code. • Assembly - Using a Assembler program to convert assembly source code to object code. Linking: • The creation of a single executable file from multiple object files. The file created, after linking is ready to be loaded into memory and executed by the system. • Using a Linker program to convert object code to executable code. Multiple units of object codes are linked to together in this step.
  • 41. Executing a C Program Process of Compilation and linking in C program:
  • 42. DATA TYPES IN C • Data type is the type of data, that are going to access within the program. • C data types are defined as the data storage format that a variable can store a data to perform a specific operation. • Data types are used to define a variable before to use in a program. • Size of variable, constant and array are determined by data types. • A data type is used to  Identify the type of a variable when the variable is declared  Identify the type of the return value of a function  Identify the type of a parameter expected by a function.
  • 43. DATA TYPES IN C Void is valueless 
  • 44. DATA TYPES IN C 1.Primitive Data Type:  The primitive data types in c language are the inbuilt data types provided by the C language itself. Thus, all c compilers provide support for these data types. Integer (int):  Integer data type is used to declare a variable that can store numbers without a decimal.  The keyword used to declare a variable of integer type is “int”.  Syntax: int variable_name;
  • 45. DATA TYPES IN C Float point (float): • Float data type declares a variable that can store numbers containing a decimal number. • Syntax: float variable_name; Character (char): • Character data type declares a variable that can store a character constant. Thus, the variables declared as char data type can only store one single character. • Syntax: char variable_name;
  • 46. DATA TYPES IN C Double Data Type (double): • Double data type also declares variable that can store floating point numbers but gives precision double than that provided by float data type. • Thus, double data type are also referred to as double precision data type. • Syntax: double variable_name; Valueless (void): • void data type does not create any variable but returns an empty set of values. Thus, we can say that it stores null. • Syntax: void variable_name;
  • 49. DATA TYPES IN C 2.Derived Data Types • Derived Data Type are a derivative of primitive data types known as arrays, pointer and function. • Array – A finite sequence (or table) of variables of the same data type • String – An array of character variables • Structure – A collection of related variables of the same and/or different data types. The structure is called a record and the variables in the record are called members or fields. 3.User Defined Data Types: • User defined data types are those data types which are defined by the user/programmer himself. • Structure, union and enum are user defined data types. • These are also referred to as composite data types.