SlideShare a Scribd company logo
C Programming
(Part 3)
BY:SURBHI SAROHA
SYLLABUS
 Structures
 Unions
 Pointers
 I/O statements
 Debugging
 Testing and verification techniques
Structures
 Arrays allow to define type of variables that can hold several data items of
the same kind.
 Similarly structure is another user defined data type available in C that
allows to combine data items of different kinds.
 Structures are used to represent a record.
 Suppose you want to keep track of your books in a library. You might want
to track the following attributes about each book −
 Title
 Author
 Subject
 Book ID
EXAMPLE
 struct Books {
 char title[50];
 char author[50];
 char subject[100];
 int book_id;
 } book;
EXAMPLE
 #include <stdio.h>
 #include <string.h>
 struct Books {
 char title[50];
 char author[50];
 char subject[100];
 int book_id;
 };
 int main( ) {
 struct Books Book1; /* Declare Book1 of type Book */
 struct Books Book2; /* Declare Book2 of type Book */
CONT….
 /* book 1 specification */
 strcpy( Book1.title, "C Programming");
 strcpy( Book1.author, "Nuha Ali");
 strcpy( Book1.subject, "C Programming Tutorial");
 Book1.book_id = 6495407;
 /* book 2 specification */
 strcpy( Book2.title, "Telecom Billing");
 strcpy( Book2.author, "Zara Ali");
 strcpy( Book2.subject, "Telecom Billing Tutorial");
 Book2.book_id = 6495700;

CONT…
 /* print Book1 info */
 printf( "Book 1 title : %sn", Book1.title);
 printf( "Book 1 author : %sn", Book1.author);
 printf( "Book 1 subject : %sn", Book1.subject);
 printf( "Book 1 book_id : %dn", Book1.book_id);
 /* print Book2 info */
 printf( "Book 2 title : %sn", Book2.title);
 printf( "Book 2 author : %sn", Book2.author);
 printf( "Book 2 subject : %sn", Book2.subject);
 printf( "Book 2 book_id : %dn", Book2.book_id);
 return 0;
 }
OUTPUT
 Book 1 title : C Programming
 Book 1 author : Nuha Ali
 Book 1 subject : C Programming Tutorial
 Book 1 book_id : 6495407
 Book 2 title : Telecom Billing
 Book 2 author : Zara Ali
 Book 2 subject : Telecom Billing Tutorial
 Book 2 book_id : 6495700
Unions
 A union is a special data type available in C that allows to store different data types in the
same memory location.
 You can define a union with many members, but only one member can contain a value at any
given time.
 Unions provide an efficient way of using the same memory location for multiple-purpose.
 The format of the union statement is as follows −
 union [union tag] {
 member definition;
 member definition;
 ...
 member definition;
 } [one or more union variables];
EXAMPLE
 union Data {
 int i;
 float f;
 char str[20];
 } data;
EXAMPLE
 #include <stdio.h>
 #include <string.h>
 union Data {
 int i;
 float f;
 char str[20];
 };
 int main( ) {
 union Data data;
 printf( "Memory size occupied by data : %dn", sizeof(data));
 return 0;
 }
 OUTPUT
 Memory size occupied by data : 20
Pointers
 A pointer is a variable whose value is the address of another variable, i.e.,
direct address of the memory location.
 Like any variable or constant, you must declare a pointer before using it to
store any variable address.
 The general form of a pointer variable declaration is −
 type *var-name;
 Here, type is the pointer's base type; it must be a valid C data type and var-
name is the name of the pointer variable. The asterisk * used to declare a
pointer is the same asterisk used for multiplication.
 int *ip; /* pointer to an integer */
 double *dp; /* pointer to a double */
 float *fp; /* pointer to a float */
 char *ch /* pointer to a character */
EXAMPLE
 #include <stdio.h>
 int main () {
 int var = 20; /* actual variable declaration */
 int *ip; /* pointer variable declaration */
 ip = &var; /* store address of var in pointer variable*/
 printf("Address of var variable: %xn", &var );
 /* address stored in pointer variable */
 printf("Address stored in ip variable: %xn", ip );
 /* access the value using the pointer */
 printf("Value of *ip variable: %dn", *ip );
 return 0;
 }
OUTPUT
 Address of var variable: bffd8b3c
 Address stored in ip variable: bffd8b3c
 Value of *ip variable: 20
I/O statements
 There are some library functions which are available for transferring the information
between the computer and the standard input and output devices.
 Some of the input and output functions are as follows:
i) printf
This function is used for displaying the output on the screen i.e the data is moved from
the computer memory to the output device.
Syntax:
printf(“format string”, arg1, arg2, …..);
In the above syntax, 'format string' will contain the information that is formatted. They
are the general characters which will be displayed as they are .
arg1, arg2 are the output data items.
Example: Demonstrating the printf function
printf(“Enter a value:”);
Cont…
 printf will generally examine from left to right of the string.
 The characters are displayed on the screen in the manner they are encountered until it
comes across % or .
 Once it comes across the conversion specifiers it will take the first argument and print it
in the format given.
 ii) scanf
scanf is used when we enter data by using an input device.
Syntax:
scanf (“format string”, &arg1, &arg2, …..);
The number of items which are successful are returned.
Format string consists of the conversion specifier. Arguments can be variables or array
name and represent the address of the variable. Each variable must be preceded by an
ampersand (&). Array names should never begin with an ampersand.
Cont…
 Example: Demonstrating scanf
int avg;
float per;
char grade;
scanf(“%d %f %c”,&avg, &per, &grade):
scanf works totally opposite to printf. The input is read, interpret using the conversion
specifier and stores it in the given variable.
 The conversion specifier for scanf is the same as printf.
 scanf reads the characters from the input as long as the characters match or it will
terminate. The order of the characters that are entered are not important.
 It requires an enter key in order to accept an input.
 iii) getch
This function is used to input a single character. The character is read instantly and it
does not require an enter key to be pressed. The character type is returned but it does
not echo on the screen.
Cont….
 Syntax:
int getch(void);
ch=getch();
where,
ch - assigned the character that is returned by getch.
iv) putch
this function is a counterpart of getch. Which means that it will display a single character
on the screen. The character that is displayed is returned.
Syntax:
int putch(int);
putch(ch);
where,
ch - the character that is to be printed.
Cont…
 v) getch
This function is used to input a single character. The main difference between
getch and getche is that getche displays the (echoes) the character that we
type on the screen.
Syntax:
int getch(void);
ch=getche();
vi) getchar
This function is used to input a single character. The enter key is pressed which
is followed by the character that is typed. The character that is entered is
echoed.
Syntax:
ch=getchar;
Cont…
 vii) putchar
This function is the other side of getchar. A single character is displayed on the
screen.
Syntax:
putchar(ch);
viii) gets and puts
They help in transferring the strings between the computer and the standard
input-output devices. Only single arguments are accepted. The arguments
must be such that it represents a string. It may include white space characters.
If gets is used enter key has to be pressed for ending the string. The gets and
puts function are used to offer simple alternatives of scanf and printf for
reading and displaying.
EXAMPLE
 #include <stdio.h>
void main()
{
char line[30];
gets (line);
puts (line);
}
Debugging
 Basic method of all debugging:
1. Know what your program is supposed to do.
2. Detect when it doesn't.
3. Fix it.
Debugging is a methodical process of finding and reducing the number of bugs (or defects)
in a computer program, thus making it behave as originally expected.
There are two main types of errors that need debugging:
I Compile-time: These occur due to misuse of language constructs, such as syntax errors.
Normally fairly easy to find by using compiler tools and warnings to fix reported problems.
I Run-time: These are much harder to figure out, as they cause the program to generate
incorrect output (or “crash”) during execution.
Testing and verification techniques
 Verification is the process of evaluating work-products of a development
phase to determine whether they meet the specified requirements.
 verification ensures that the product is built according to the requirements
and design specifications. It also answers to the question, Are we building
the product right?
 Verification Testing - Workflow:
 verification testing can be best demonstrated using V-Model. The artefacts
such as test Plans, requirement specification, design, code and test cases
are evaluated.
Verification Testing
THANK YOU 
Ad

More Related Content

What's hot (20)

[ITP - Lecture 16] Structures in C/C++
[ITP - Lecture 16] Structures in C/C++[ITP - Lecture 16] Structures in C/C++
[ITP - Lecture 16] Structures in C/C++
Muhammad Hammad Waseem
 
Functions and pointers_unit_4
Functions and pointers_unit_4Functions and pointers_unit_4
Functions and pointers_unit_4
Saranya saran
 
[ITP - Lecture 17] Strings in C/C++
[ITP - Lecture 17] Strings in C/C++[ITP - Lecture 17] Strings in C/C++
[ITP - Lecture 17] Strings in C/C++
Muhammad Hammad Waseem
 
Assignment c programming
Assignment c programmingAssignment c programming
Assignment c programming
Icaii Infotech
 
Lecture 9- Control Structures 1
Lecture 9- Control Structures 1Lecture 9- Control Structures 1
Lecture 9- Control Structures 1
Md. Imran Hossain Showrov
 
Lập trình C
Lập trình CLập trình C
Lập trình C
Viet NguyenHoang
 
Concepts of C [Module 2]
Concepts of C [Module 2]Concepts of C [Module 2]
Concepts of C [Module 2]
Abhishek Sinha
 
46630497 fun-pointer-1
46630497 fun-pointer-146630497 fun-pointer-1
46630497 fun-pointer-1
AmIt Prasad
 
Mesics lecture 5 input – output in ‘c’
Mesics lecture 5   input – output in ‘c’Mesics lecture 5   input – output in ‘c’
Mesics lecture 5 input – output in ‘c’
eShikshak
 
C++ Overview PPT
C++ Overview PPTC++ Overview PPT
C++ Overview PPT
Thooyavan Venkatachalam
 
MANAGING INPUT AND OUTPUT OPERATIONS IN C MRS.SOWMYA JYOTHI.pdf
MANAGING INPUT AND OUTPUT OPERATIONS IN C    MRS.SOWMYA JYOTHI.pdfMANAGING INPUT AND OUTPUT OPERATIONS IN C    MRS.SOWMYA JYOTHI.pdf
MANAGING INPUT AND OUTPUT OPERATIONS IN C MRS.SOWMYA JYOTHI.pdf
SowmyaJyothi3
 
Input And Output
 Input And Output Input And Output
Input And Output
Ghaffar Khan
 
Unit ii ppt
Unit ii pptUnit ii ppt
Unit ii ppt
ANJALAI AMMAL MAHALINGAM ENGINEERING COLLEGE
 
C Programming Assignment
C Programming AssignmentC Programming Assignment
C Programming Assignment
Vijayananda Mohire
 
Lecture 14 - Scope Rules
Lecture 14 - Scope RulesLecture 14 - Scope Rules
Lecture 14 - Scope Rules
Md. Imran Hossain Showrov
 
Lập trình C
Lập trình CLập trình C
Lập trình C
Viet NguyenHoang
 
Arrays
ArraysArrays
Arrays
Saranya saran
 
C Programming Unit-2
C Programming Unit-2C Programming Unit-2
C Programming Unit-2
Vikram Nandini
 
C Programming Unit-3
C Programming Unit-3C Programming Unit-3
C Programming Unit-3
Vikram Nandini
 
STRINGS IN C MRS.SOWMYA JYOTHI.pdf
STRINGS IN C MRS.SOWMYA JYOTHI.pdfSTRINGS IN C MRS.SOWMYA JYOTHI.pdf
STRINGS IN C MRS.SOWMYA JYOTHI.pdf
SowmyaJyothi3
 

Similar to C programming(part 3) (20)

basic C PROGRAMMING for first years .pptx
basic C  PROGRAMMING for first years  .pptxbasic C  PROGRAMMING for first years  .pptx
basic C PROGRAMMING for first years .pptx
divyasindhu040
 
qb unit2 solve eem201.pdf
qb unit2 solve eem201.pdfqb unit2 solve eem201.pdf
qb unit2 solve eem201.pdf
Yashsharma304389
 
fds unit1.docx
fds unit1.docxfds unit1.docx
fds unit1.docx
AzhagesvaranTamilsel
 
Programming in C - interview questions.pdf
Programming in C - interview questions.pdfProgramming in C - interview questions.pdf
Programming in C - interview questions.pdf
SergiuMatei7
 
Esoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programmingEsoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programming
Rasan Samarasinghe
 
C,c++ interview q&a
C,c++ interview q&aC,c++ interview q&a
C,c++ interview q&a
Kumaran K
 
Notes(1).pptx
Notes(1).pptxNotes(1).pptx
Notes(1).pptx
InfinityWorld3
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial
javaTpoint s
 
C Programming - Basics of c -history of c
C Programming - Basics of c -history of cC Programming - Basics of c -history of c
C Programming - Basics of c -history of c
DHIVYAB17
 
Fundamental of C Programming Language and Basic Input/Output Function
  Fundamental of C Programming Language and Basic Input/Output Function  Fundamental of C Programming Language and Basic Input/Output Function
Fundamental of C Programming Language and Basic Input/Output Function
imtiazalijoono
 
C programming session 01
C programming session 01C programming session 01
C programming session 01
Dushmanta Nath
 
Fundamentals of Programming Constructs.pptx
Fundamentals of  Programming Constructs.pptxFundamentals of  Programming Constructs.pptx
Fundamentals of Programming Constructs.pptx
vijayapraba1
 
the refernce of programming C notes ppt.pptx
the refernce of programming C notes ppt.pptxthe refernce of programming C notes ppt.pptx
the refernce of programming C notes ppt.pptx
AnkitaVerma776806
 
88 c-programs
88 c-programs88 c-programs
88 c-programs
Leandro Schenone
 
C Programming Unit-1
C Programming Unit-1C Programming Unit-1
C Programming Unit-1
Vikram Nandini
 
C_Progragramming_language_Tutorial_ppt_f.pptx
C_Progragramming_language_Tutorial_ppt_f.pptxC_Progragramming_language_Tutorial_ppt_f.pptx
C_Progragramming_language_Tutorial_ppt_f.pptx
maaithilisaravanan
 
Chapter3
Chapter3Chapter3
Chapter3
Kamran
 
C librabry 55 functions.pdfljhghmhiguyftg
C librabry 55 functions.pdfljhghmhiguyftgC librabry 55 functions.pdfljhghmhiguyftg
C librabry 55 functions.pdfljhghmhiguyftg
saimukesh19
 
C Programming Language Introduction and C Tokens.pdf
C Programming Language Introduction and C Tokens.pdfC Programming Language Introduction and C Tokens.pdf
C Programming Language Introduction and C Tokens.pdf
poongothai11
 
Hooking signals and dumping the callstack
Hooking signals and dumping the callstackHooking signals and dumping the callstack
Hooking signals and dumping the callstack
Thierry Gayet
 
basic C PROGRAMMING for first years .pptx
basic C  PROGRAMMING for first years  .pptxbasic C  PROGRAMMING for first years  .pptx
basic C PROGRAMMING for first years .pptx
divyasindhu040
 
Programming in C - interview questions.pdf
Programming in C - interview questions.pdfProgramming in C - interview questions.pdf
Programming in C - interview questions.pdf
SergiuMatei7
 
Esoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programmingEsoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programming
Rasan Samarasinghe
 
C,c++ interview q&a
C,c++ interview q&aC,c++ interview q&a
C,c++ interview q&a
Kumaran K
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial
javaTpoint s
 
C Programming - Basics of c -history of c
C Programming - Basics of c -history of cC Programming - Basics of c -history of c
C Programming - Basics of c -history of c
DHIVYAB17
 
Fundamental of C Programming Language and Basic Input/Output Function
  Fundamental of C Programming Language and Basic Input/Output Function  Fundamental of C Programming Language and Basic Input/Output Function
Fundamental of C Programming Language and Basic Input/Output Function
imtiazalijoono
 
C programming session 01
C programming session 01C programming session 01
C programming session 01
Dushmanta Nath
 
Fundamentals of Programming Constructs.pptx
Fundamentals of  Programming Constructs.pptxFundamentals of  Programming Constructs.pptx
Fundamentals of Programming Constructs.pptx
vijayapraba1
 
the refernce of programming C notes ppt.pptx
the refernce of programming C notes ppt.pptxthe refernce of programming C notes ppt.pptx
the refernce of programming C notes ppt.pptx
AnkitaVerma776806
 
C_Progragramming_language_Tutorial_ppt_f.pptx
C_Progragramming_language_Tutorial_ppt_f.pptxC_Progragramming_language_Tutorial_ppt_f.pptx
C_Progragramming_language_Tutorial_ppt_f.pptx
maaithilisaravanan
 
Chapter3
Chapter3Chapter3
Chapter3
Kamran
 
C librabry 55 functions.pdfljhghmhiguyftg
C librabry 55 functions.pdfljhghmhiguyftgC librabry 55 functions.pdfljhghmhiguyftg
C librabry 55 functions.pdfljhghmhiguyftg
saimukesh19
 
C Programming Language Introduction and C Tokens.pdf
C Programming Language Introduction and C Tokens.pdfC Programming Language Introduction and C Tokens.pdf
C Programming Language Introduction and C Tokens.pdf
poongothai11
 
Hooking signals and dumping the callstack
Hooking signals and dumping the callstackHooking signals and dumping the callstack
Hooking signals and dumping the callstack
Thierry Gayet
 
Ad

More from Dr. SURBHI SAROHA (20)

Deep learning(UNIT 3) BY Ms SURBHI SAROHA
Deep learning(UNIT 3) BY Ms SURBHI SAROHADeep learning(UNIT 3) BY Ms SURBHI SAROHA
Deep learning(UNIT 3) BY Ms SURBHI SAROHA
Dr. SURBHI SAROHA
 
MOBILE COMPUTING UNIT 2 by surbhi saroha
MOBILE COMPUTING UNIT 2 by surbhi sarohaMOBILE COMPUTING UNIT 2 by surbhi saroha
MOBILE COMPUTING UNIT 2 by surbhi saroha
Dr. SURBHI SAROHA
 
Mobile Computing UNIT 1 by surbhi saroha
Mobile Computing UNIT 1 by surbhi sarohaMobile Computing UNIT 1 by surbhi saroha
Mobile Computing UNIT 1 by surbhi saroha
Dr. SURBHI SAROHA
 
DEEP LEARNING (UNIT 2 ) by surbhi saroha
DEEP LEARNING (UNIT 2 ) by surbhi sarohaDEEP LEARNING (UNIT 2 ) by surbhi saroha
DEEP LEARNING (UNIT 2 ) by surbhi saroha
Dr. SURBHI SAROHA
 
Introduction to Deep Leaning(UNIT 1).pptx
Introduction to Deep Leaning(UNIT 1).pptxIntroduction to Deep Leaning(UNIT 1).pptx
Introduction to Deep Leaning(UNIT 1).pptx
Dr. SURBHI SAROHA
 
Cloud Computing (Infrastructure as a Service)UNIT 2
Cloud Computing (Infrastructure as a Service)UNIT 2Cloud Computing (Infrastructure as a Service)UNIT 2
Cloud Computing (Infrastructure as a Service)UNIT 2
Dr. SURBHI SAROHA
 
Management Information System(Unit 2).pptx
Management Information System(Unit 2).pptxManagement Information System(Unit 2).pptx
Management Information System(Unit 2).pptx
Dr. SURBHI SAROHA
 
Searching in Data Structure(Linear search and Binary search)
Searching in Data Structure(Linear search and Binary search)Searching in Data Structure(Linear search and Binary search)
Searching in Data Structure(Linear search and Binary search)
Dr. SURBHI SAROHA
 
Management Information System(UNIT 1).pptx
Management Information System(UNIT 1).pptxManagement Information System(UNIT 1).pptx
Management Information System(UNIT 1).pptx
Dr. SURBHI SAROHA
 
Introduction to Cloud Computing(UNIT 1).pptx
Introduction to Cloud Computing(UNIT 1).pptxIntroduction to Cloud Computing(UNIT 1).pptx
Introduction to Cloud Computing(UNIT 1).pptx
Dr. SURBHI SAROHA
 
JAVA (UNIT 5)
JAVA (UNIT 5)JAVA (UNIT 5)
JAVA (UNIT 5)
Dr. SURBHI SAROHA
 
DBMS (UNIT 5)
DBMS (UNIT 5)DBMS (UNIT 5)
DBMS (UNIT 5)
Dr. SURBHI SAROHA
 
DBMS UNIT 4
DBMS UNIT 4DBMS UNIT 4
DBMS UNIT 4
Dr. SURBHI SAROHA
 
JAVA(UNIT 4)
JAVA(UNIT 4)JAVA(UNIT 4)
JAVA(UNIT 4)
Dr. SURBHI SAROHA
 
OOPs & C++(UNIT 5)
OOPs & C++(UNIT 5)OOPs & C++(UNIT 5)
OOPs & C++(UNIT 5)
Dr. SURBHI SAROHA
 
OOPS & C++(UNIT 4)
OOPS & C++(UNIT 4)OOPS & C++(UNIT 4)
OOPS & C++(UNIT 4)
Dr. SURBHI SAROHA
 
DBMS UNIT 3
DBMS UNIT 3DBMS UNIT 3
DBMS UNIT 3
Dr. SURBHI SAROHA
 
JAVA (UNIT 3)
JAVA (UNIT 3)JAVA (UNIT 3)
JAVA (UNIT 3)
Dr. SURBHI SAROHA
 
Keys in dbms(UNIT 2)
Keys in dbms(UNIT 2)Keys in dbms(UNIT 2)
Keys in dbms(UNIT 2)
Dr. SURBHI SAROHA
 
DBMS (UNIT 2)
DBMS (UNIT 2)DBMS (UNIT 2)
DBMS (UNIT 2)
Dr. SURBHI SAROHA
 
Deep learning(UNIT 3) BY Ms SURBHI SAROHA
Deep learning(UNIT 3) BY Ms SURBHI SAROHADeep learning(UNIT 3) BY Ms SURBHI SAROHA
Deep learning(UNIT 3) BY Ms SURBHI SAROHA
Dr. SURBHI SAROHA
 
MOBILE COMPUTING UNIT 2 by surbhi saroha
MOBILE COMPUTING UNIT 2 by surbhi sarohaMOBILE COMPUTING UNIT 2 by surbhi saroha
MOBILE COMPUTING UNIT 2 by surbhi saroha
Dr. SURBHI SAROHA
 
Mobile Computing UNIT 1 by surbhi saroha
Mobile Computing UNIT 1 by surbhi sarohaMobile Computing UNIT 1 by surbhi saroha
Mobile Computing UNIT 1 by surbhi saroha
Dr. SURBHI SAROHA
 
DEEP LEARNING (UNIT 2 ) by surbhi saroha
DEEP LEARNING (UNIT 2 ) by surbhi sarohaDEEP LEARNING (UNIT 2 ) by surbhi saroha
DEEP LEARNING (UNIT 2 ) by surbhi saroha
Dr. SURBHI SAROHA
 
Introduction to Deep Leaning(UNIT 1).pptx
Introduction to Deep Leaning(UNIT 1).pptxIntroduction to Deep Leaning(UNIT 1).pptx
Introduction to Deep Leaning(UNIT 1).pptx
Dr. SURBHI SAROHA
 
Cloud Computing (Infrastructure as a Service)UNIT 2
Cloud Computing (Infrastructure as a Service)UNIT 2Cloud Computing (Infrastructure as a Service)UNIT 2
Cloud Computing (Infrastructure as a Service)UNIT 2
Dr. SURBHI SAROHA
 
Management Information System(Unit 2).pptx
Management Information System(Unit 2).pptxManagement Information System(Unit 2).pptx
Management Information System(Unit 2).pptx
Dr. SURBHI SAROHA
 
Searching in Data Structure(Linear search and Binary search)
Searching in Data Structure(Linear search and Binary search)Searching in Data Structure(Linear search and Binary search)
Searching in Data Structure(Linear search and Binary search)
Dr. SURBHI SAROHA
 
Management Information System(UNIT 1).pptx
Management Information System(UNIT 1).pptxManagement Information System(UNIT 1).pptx
Management Information System(UNIT 1).pptx
Dr. SURBHI SAROHA
 
Introduction to Cloud Computing(UNIT 1).pptx
Introduction to Cloud Computing(UNIT 1).pptxIntroduction to Cloud Computing(UNIT 1).pptx
Introduction to Cloud Computing(UNIT 1).pptx
Dr. SURBHI SAROHA
 
Ad

Recently uploaded (20)

New Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptxNew Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptx
milanasargsyan5
 
How to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POSHow to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POS
Celine George
 
Introduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe EngineeringIntroduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe Engineering
Damian T. Gordon
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Celine George
 
Metamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative JourneyMetamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative Journey
Arshad Shaikh
 
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
Celine George
 
Operations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdfOperations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdf
Arab Academy for Science, Technology and Maritime Transport
 
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulsepulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
sushreesangita003
 
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACYUNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
DR.PRISCILLA MARY J
 
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptxSCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
Ronisha Das
 
Handling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptxHandling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptx
AuthorAIDNationalRes
 
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Library Association of Ireland
 
How to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of saleHow to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of sale
Celine George
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 4-30-2025.pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 4-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-30-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
Anti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptxAnti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptx
Mayuri Chavan
 
Sinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_NameSinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_Name
keshanf79
 
How to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 WebsiteHow to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 Website
Celine George
 
Biophysics Chapter 3 Methods of Studying Macromolecules.pdf
Biophysics Chapter 3 Methods of Studying Macromolecules.pdfBiophysics Chapter 3 Methods of Studying Macromolecules.pdf
Biophysics Chapter 3 Methods of Studying Macromolecules.pdf
PKLI-Institute of Nursing and Allied Health Sciences Lahore , Pakistan.
 
How to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odooHow to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odoo
Celine George
 
New Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptxNew Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptx
milanasargsyan5
 
How to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POSHow to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POS
Celine George
 
Introduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe EngineeringIntroduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe Engineering
Damian T. Gordon
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Celine George
 
Metamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative JourneyMetamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative Journey
Arshad Shaikh
 
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
Celine George
 
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulsepulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
sushreesangita003
 
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACYUNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
DR.PRISCILLA MARY J
 
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptxSCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
Ronisha Das
 
Handling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptxHandling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptx
AuthorAIDNationalRes
 
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Library Association of Ireland
 
How to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of saleHow to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of sale
Celine George
 
Anti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptxAnti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptx
Mayuri Chavan
 
Sinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_NameSinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_Name
keshanf79
 
How to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 WebsiteHow to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 Website
Celine George
 
How to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odooHow to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odoo
Celine George
 

C programming(part 3)

  • 2. SYLLABUS  Structures  Unions  Pointers  I/O statements  Debugging  Testing and verification techniques
  • 3. Structures  Arrays allow to define type of variables that can hold several data items of the same kind.  Similarly structure is another user defined data type available in C that allows to combine data items of different kinds.  Structures are used to represent a record.  Suppose you want to keep track of your books in a library. You might want to track the following attributes about each book −  Title  Author  Subject  Book ID
  • 4. EXAMPLE  struct Books {  char title[50];  char author[50];  char subject[100];  int book_id;  } book;
  • 5. EXAMPLE  #include <stdio.h>  #include <string.h>  struct Books {  char title[50];  char author[50];  char subject[100];  int book_id;  };  int main( ) {  struct Books Book1; /* Declare Book1 of type Book */  struct Books Book2; /* Declare Book2 of type Book */
  • 6. CONT….  /* book 1 specification */  strcpy( Book1.title, "C Programming");  strcpy( Book1.author, "Nuha Ali");  strcpy( Book1.subject, "C Programming Tutorial");  Book1.book_id = 6495407;  /* book 2 specification */  strcpy( Book2.title, "Telecom Billing");  strcpy( Book2.author, "Zara Ali");  strcpy( Book2.subject, "Telecom Billing Tutorial");  Book2.book_id = 6495700; 
  • 7. CONT…  /* print Book1 info */  printf( "Book 1 title : %sn", Book1.title);  printf( "Book 1 author : %sn", Book1.author);  printf( "Book 1 subject : %sn", Book1.subject);  printf( "Book 1 book_id : %dn", Book1.book_id);  /* print Book2 info */  printf( "Book 2 title : %sn", Book2.title);  printf( "Book 2 author : %sn", Book2.author);  printf( "Book 2 subject : %sn", Book2.subject);  printf( "Book 2 book_id : %dn", Book2.book_id);  return 0;  }
  • 8. OUTPUT  Book 1 title : C Programming  Book 1 author : Nuha Ali  Book 1 subject : C Programming Tutorial  Book 1 book_id : 6495407  Book 2 title : Telecom Billing  Book 2 author : Zara Ali  Book 2 subject : Telecom Billing Tutorial  Book 2 book_id : 6495700
  • 9. Unions  A union is a special data type available in C that allows to store different data types in the same memory location.  You can define a union with many members, but only one member can contain a value at any given time.  Unions provide an efficient way of using the same memory location for multiple-purpose.  The format of the union statement is as follows −  union [union tag] {  member definition;  member definition;  ...  member definition;  } [one or more union variables];
  • 10. EXAMPLE  union Data {  int i;  float f;  char str[20];  } data;
  • 11. EXAMPLE  #include <stdio.h>  #include <string.h>  union Data {  int i;  float f;  char str[20];  };  int main( ) {  union Data data;  printf( "Memory size occupied by data : %dn", sizeof(data));  return 0;  }  OUTPUT  Memory size occupied by data : 20
  • 12. Pointers  A pointer is a variable whose value is the address of another variable, i.e., direct address of the memory location.  Like any variable or constant, you must declare a pointer before using it to store any variable address.  The general form of a pointer variable declaration is −  type *var-name;  Here, type is the pointer's base type; it must be a valid C data type and var- name is the name of the pointer variable. The asterisk * used to declare a pointer is the same asterisk used for multiplication.  int *ip; /* pointer to an integer */  double *dp; /* pointer to a double */  float *fp; /* pointer to a float */  char *ch /* pointer to a character */
  • 13. EXAMPLE  #include <stdio.h>  int main () {  int var = 20; /* actual variable declaration */  int *ip; /* pointer variable declaration */  ip = &var; /* store address of var in pointer variable*/  printf("Address of var variable: %xn", &var );  /* address stored in pointer variable */  printf("Address stored in ip variable: %xn", ip );  /* access the value using the pointer */  printf("Value of *ip variable: %dn", *ip );  return 0;  }
  • 14. OUTPUT  Address of var variable: bffd8b3c  Address stored in ip variable: bffd8b3c  Value of *ip variable: 20
  • 15. I/O statements  There are some library functions which are available for transferring the information between the computer and the standard input and output devices.  Some of the input and output functions are as follows: i) printf This function is used for displaying the output on the screen i.e the data is moved from the computer memory to the output device. Syntax: printf(“format string”, arg1, arg2, …..); In the above syntax, 'format string' will contain the information that is formatted. They are the general characters which will be displayed as they are . arg1, arg2 are the output data items. Example: Demonstrating the printf function printf(“Enter a value:”);
  • 16. Cont…  printf will generally examine from left to right of the string.  The characters are displayed on the screen in the manner they are encountered until it comes across % or .  Once it comes across the conversion specifiers it will take the first argument and print it in the format given.  ii) scanf scanf is used when we enter data by using an input device. Syntax: scanf (“format string”, &arg1, &arg2, …..); The number of items which are successful are returned. Format string consists of the conversion specifier. Arguments can be variables or array name and represent the address of the variable. Each variable must be preceded by an ampersand (&). Array names should never begin with an ampersand.
  • 17. Cont…  Example: Demonstrating scanf int avg; float per; char grade; scanf(“%d %f %c”,&avg, &per, &grade): scanf works totally opposite to printf. The input is read, interpret using the conversion specifier and stores it in the given variable.  The conversion specifier for scanf is the same as printf.  scanf reads the characters from the input as long as the characters match or it will terminate. The order of the characters that are entered are not important.  It requires an enter key in order to accept an input.  iii) getch This function is used to input a single character. The character is read instantly and it does not require an enter key to be pressed. The character type is returned but it does not echo on the screen.
  • 18. Cont….  Syntax: int getch(void); ch=getch(); where, ch - assigned the character that is returned by getch. iv) putch this function is a counterpart of getch. Which means that it will display a single character on the screen. The character that is displayed is returned. Syntax: int putch(int); putch(ch); where, ch - the character that is to be printed.
  • 19. Cont…  v) getch This function is used to input a single character. The main difference between getch and getche is that getche displays the (echoes) the character that we type on the screen. Syntax: int getch(void); ch=getche(); vi) getchar This function is used to input a single character. The enter key is pressed which is followed by the character that is typed. The character that is entered is echoed. Syntax: ch=getchar;
  • 20. Cont…  vii) putchar This function is the other side of getchar. A single character is displayed on the screen. Syntax: putchar(ch); viii) gets and puts They help in transferring the strings between the computer and the standard input-output devices. Only single arguments are accepted. The arguments must be such that it represents a string. It may include white space characters. If gets is used enter key has to be pressed for ending the string. The gets and puts function are used to offer simple alternatives of scanf and printf for reading and displaying.
  • 21. EXAMPLE  #include <stdio.h> void main() { char line[30]; gets (line); puts (line); }
  • 22. Debugging  Basic method of all debugging: 1. Know what your program is supposed to do. 2. Detect when it doesn't. 3. Fix it. Debugging is a methodical process of finding and reducing the number of bugs (or defects) in a computer program, thus making it behave as originally expected. There are two main types of errors that need debugging: I Compile-time: These occur due to misuse of language constructs, such as syntax errors. Normally fairly easy to find by using compiler tools and warnings to fix reported problems. I Run-time: These are much harder to figure out, as they cause the program to generate incorrect output (or “crash”) during execution.
  • 23. Testing and verification techniques  Verification is the process of evaluating work-products of a development phase to determine whether they meet the specified requirements.  verification ensures that the product is built according to the requirements and design specifications. It also answers to the question, Are we building the product right?  Verification Testing - Workflow:  verification testing can be best demonstrated using V-Model. The artefacts such as test Plans, requirement specification, design, code and test cases are evaluated.