SlideShare a Scribd company logo
1 of 25
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 

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++
 
Functions and pointers_unit_4
Functions and pointers_unit_4Functions and pointers_unit_4
Functions and pointers_unit_4
 
[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++
 
Assignment c programming
Assignment c programmingAssignment c programming
Assignment c programming
 
Lecture 9- Control Structures 1
Lecture 9- Control Structures 1Lecture 9- Control Structures 1
Lecture 9- Control Structures 1
 
Lập trình C
Lập trình CLập trình C
Lập trình C
 
Concepts of C [Module 2]
Concepts of C [Module 2]Concepts of C [Module 2]
Concepts of C [Module 2]
 
46630497 fun-pointer-1
46630497 fun-pointer-146630497 fun-pointer-1
46630497 fun-pointer-1
 
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’
 
C++ Overview PPT
C++ Overview PPTC++ Overview PPT
C++ Overview PPT
 
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
 
Input And Output
 Input And Output Input And Output
Input And Output
 
Unit ii ppt
Unit ii pptUnit ii ppt
Unit ii ppt
 
C Programming Assignment
C Programming AssignmentC Programming Assignment
C Programming Assignment
 
Lecture 14 - Scope Rules
Lecture 14 - Scope RulesLecture 14 - Scope Rules
Lecture 14 - Scope Rules
 
Lập trình C
Lập trình CLập trình C
Lập trình C
 
Arrays
ArraysArrays
Arrays
 
C Programming Unit-2
C Programming Unit-2C Programming Unit-2
C Programming Unit-2
 
C Programming Unit-3
C Programming Unit-3C Programming Unit-3
C Programming Unit-3
 
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
 

Similar to C programming(part 3)

Programming in C - interview questions.pdf
Programming in C - interview questions.pdfProgramming in C - interview questions.pdf
Programming in C - interview questions.pdfSergiuMatei7
 
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++ programmingRasan Samarasinghe
 
C,c++ interview q&a
C,c++ interview q&aC,c++ interview q&a
C,c++ interview q&aKumaran K
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial javaTpoint s
 
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 Functionimtiazalijoono
 
C programming session 01
C programming session 01C programming session 01
C programming session 01Dushmanta Nath
 
Fundamentals of Programming Constructs.pptx
Fundamentals of  Programming Constructs.pptxFundamentals of  Programming Constructs.pptx
Fundamentals of Programming Constructs.pptxvijayapraba1
 
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.pptxAnkitaVerma776806
 
Chapter3
Chapter3Chapter3
Chapter3Kamran
 
Hooking signals and dumping the callstack
Hooking signals and dumping the callstackHooking signals and dumping the callstack
Hooking signals and dumping the callstackThierry Gayet
 
Introduction to C Unit 1
Introduction to C Unit 1Introduction to C Unit 1
Introduction to C Unit 1SURBHI SAROHA
 

Similar to C programming(part 3) (20)

qb unit2 solve eem201.pdf
qb unit2 solve eem201.pdfqb unit2 solve eem201.pdf
qb unit2 solve eem201.pdf
 
fds unit1.docx
fds unit1.docxfds unit1.docx
fds unit1.docx
 
Programming in C - interview questions.pdf
Programming in C - interview questions.pdfProgramming in C - interview questions.pdf
Programming in C - interview questions.pdf
 
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
 
C,c++ interview q&a
C,c++ interview q&aC,c++ interview q&a
C,c++ interview q&a
 
Notes(1).pptx
Notes(1).pptxNotes(1).pptx
Notes(1).pptx
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial
 
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
 
C programming session 01
C programming session 01C programming session 01
C programming session 01
 
Fundamentals of Programming Constructs.pptx
Fundamentals of  Programming Constructs.pptxFundamentals of  Programming Constructs.pptx
Fundamentals of Programming Constructs.pptx
 
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
 
88 c-programs
88 c-programs88 c-programs
88 c-programs
 
C Programming Unit-1
C Programming Unit-1C Programming Unit-1
C Programming Unit-1
 
Chapter3
Chapter3Chapter3
Chapter3
 
Hooking signals and dumping the callstack
Hooking signals and dumping the callstackHooking signals and dumping the callstack
Hooking signals and dumping the callstack
 
Introduction to C Unit 1
Introduction to C Unit 1Introduction to C Unit 1
Introduction to C Unit 1
 
Ppt of c vs c#
Ppt of c vs c#Ppt of c vs c#
Ppt of c vs c#
 
C notes.pdf
C notes.pdfC notes.pdf
C notes.pdf
 
U5 SPC.pptx
U5 SPC.pptxU5 SPC.pptx
U5 SPC.pptx
 
U5 SPC.pptx
U5 SPC.pptxU5 SPC.pptx
U5 SPC.pptx
 

More from 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 2SURBHI SAROHA
 
Management Information System(Unit 2).pptx
Management Information System(Unit 2).pptxManagement Information System(Unit 2).pptx
Management Information System(Unit 2).pptxSURBHI 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)SURBHI SAROHA
 
Management Information System(UNIT 1).pptx
Management Information System(UNIT 1).pptxManagement Information System(UNIT 1).pptx
Management Information System(UNIT 1).pptxSURBHI 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).pptxSURBHI SAROHA
 
Keys in dbms(UNIT 2)
Keys in dbms(UNIT 2)Keys in dbms(UNIT 2)
Keys in dbms(UNIT 2)SURBHI SAROHA
 
Database Management System(UNIT 1)
Database Management System(UNIT 1)Database Management System(UNIT 1)
Database Management System(UNIT 1)SURBHI SAROHA
 
Object-Oriented Programming with Java UNIT 1
Object-Oriented Programming with Java UNIT 1Object-Oriented Programming with Java UNIT 1
Object-Oriented Programming with Java UNIT 1SURBHI SAROHA
 
Database Management System(UNIT 1)
Database Management System(UNIT 1)Database Management System(UNIT 1)
Database Management System(UNIT 1)SURBHI SAROHA
 

More from SURBHI SAROHA (20)

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
 
Management Information System(Unit 2).pptx
Management Information System(Unit 2).pptxManagement Information System(Unit 2).pptx
Management Information System(Unit 2).pptx
 
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)
 
Management Information System(UNIT 1).pptx
Management Information System(UNIT 1).pptxManagement Information System(UNIT 1).pptx
Management Information System(UNIT 1).pptx
 
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
 
JAVA (UNIT 5)
JAVA (UNIT 5)JAVA (UNIT 5)
JAVA (UNIT 5)
 
DBMS (UNIT 5)
DBMS (UNIT 5)DBMS (UNIT 5)
DBMS (UNIT 5)
 
DBMS UNIT 4
DBMS UNIT 4DBMS UNIT 4
DBMS UNIT 4
 
JAVA(UNIT 4)
JAVA(UNIT 4)JAVA(UNIT 4)
JAVA(UNIT 4)
 
OOPs & C++(UNIT 5)
OOPs & C++(UNIT 5)OOPs & C++(UNIT 5)
OOPs & C++(UNIT 5)
 
OOPS & C++(UNIT 4)
OOPS & C++(UNIT 4)OOPS & C++(UNIT 4)
OOPS & C++(UNIT 4)
 
DBMS UNIT 3
DBMS UNIT 3DBMS UNIT 3
DBMS UNIT 3
 
JAVA (UNIT 3)
JAVA (UNIT 3)JAVA (UNIT 3)
JAVA (UNIT 3)
 
Keys in dbms(UNIT 2)
Keys in dbms(UNIT 2)Keys in dbms(UNIT 2)
Keys in dbms(UNIT 2)
 
DBMS (UNIT 2)
DBMS (UNIT 2)DBMS (UNIT 2)
DBMS (UNIT 2)
 
JAVA UNIT 2
JAVA UNIT 2JAVA UNIT 2
JAVA UNIT 2
 
Database Management System(UNIT 1)
Database Management System(UNIT 1)Database Management System(UNIT 1)
Database Management System(UNIT 1)
 
Object-Oriented Programming with Java UNIT 1
Object-Oriented Programming with Java UNIT 1Object-Oriented Programming with Java UNIT 1
Object-Oriented Programming with Java UNIT 1
 
Database Management System(UNIT 1)
Database Management System(UNIT 1)Database Management System(UNIT 1)
Database Management System(UNIT 1)
 
OOPs & C++ UNIT 3
OOPs & C++ UNIT 3OOPs & C++ UNIT 3
OOPs & C++ UNIT 3
 

Recently uploaded

ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdfssuserdda66b
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseAnaAcapella
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxcallscotland1987
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxAmanpreet Kaur
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 

Recently uploaded (20)

ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 

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.