SlideShare una empresa de Scribd logo
1 de 21
Unit-5
Pointer, Structure, Union
&
Intro to File Handling
Course: BCA
Subject: Programming In C Language
What is a pointer
• In a generic sense, a “pointer” is anything that tells usIn a generic sense, a “pointer” is anything that tells us
where something can be found.where something can be found.
– Addresses in the phone book
– URLs for webpages
– Road signs
Java Reference
• In Java, the name of an object is a reference to that object.In Java, the name of an object is a reference to that object.
HereHere ford is a reference to a Truck object. It contains theis a reference to a Truck object. It contains the
memory address at which the Truck object is stored.memory address at which the Truck object is stored.
Truck ford = new Truck( );
• The syntax for using the reference is pretty simple. JustThe syntax for using the reference is pretty simple. Just
use the “dot” notation.use the “dot” notation.
ford.start( );
ford.drive( 23 );
ford.turn (LEFT);
What is a pointer ?
• In C, a pointer variable (or just “pointer”) is similar toIn C, a pointer variable (or just “pointer”) is similar to
a reference in Java except thata reference in Java except that
– A pointer can contain the memory address of any variable
type (Java references only refer to objects)
– A primitive (int, char, float)
– An array
– A struct or union
– Dynamically allocated memory
– Another pointer
– A function
– There’s a lot of syntax required to create and use pointers
Why Pointers?
• They allow you to refer to large data structures in a compactThey allow you to refer to large data structures in a compact
wayway
• They facilitate sharing between different parts of programsThey facilitate sharing between different parts of programs
• They make it possible to get new memory dynamically as yourThey make it possible to get new memory dynamically as your
program is runningprogram is running
• They make it easy to represent relationships among data items.They make it easy to represent relationships among data items.
Pointer Caution
• They are a powerful low-level device.They are a powerful low-level device.
• Undisciplined use can be confusing and thus theUndisciplined use can be confusing and thus the
source of subtle, hard-to-find bugs.source of subtle, hard-to-find bugs.
– Program crashes
– Memory leaks
– Unpredictable results
C Pointer Variables
To declare a pointer variable, we must do two thingsTo declare a pointer variable, we must do two things
– Use the “*” (star) character to indicate that the variable being
defined is a pointer type.
– Indicate the type of variable to which the pointer will point
(the pointee). This is necessary because C provides
operations on pointers (e.g., *, ++, etc) whose meaning
depends on the type of the pointee.
• General declaration of a pointerGeneral declaration of a pointer
type *nameOfPointer;
Pointer Declaration
The declarationThe declaration
int *intPtr;
defines the variabledefines the variable intPtr to be a pointer to a variable of typeto be a pointer to a variable of type
int.. intPtr will contain the memory address of somewill contain the memory address of some int
variable orvariable or int array. Read this declaration asarray. Read this declaration as
– “intPtr is a pointer to an int”, or equivalently
– “*intPtr is an int”
Caution -- Be careful when defining multiple variables on the sameCaution -- Be careful when defining multiple variables on the same
line. In this definitionline. In this definition
int *intPtr, intPtr2;
intPtr is a pointer to an int, but intPtr2 is not!
Pointer Operators
The two primary operators used with pointers areThe two primary operators used with pointers are
* (star) and(star) and && (ampersand)(ampersand)
– The * operator is used to define pointer variables and to
deference a pointer. “Dereferencing” a pointer means to use
the value of the pointee.
– The & operator gives the address of a variable.
Recall the use of & in scanf( )
Pointer Examples
int x = 1, y = 2, z[10];
int *ip; /* ip is a pointer to an int */
ip = &x; /* ip points to (contains the memory address of) x */
y = *ip; /* y is now 1, indirectly copied from x using ip */
*ip = 0; /* x is now 0 */
ip = &z[5]; /* ip now points to z[5] */
If ip points to x, then *ip can be used anywhere x can be used so in this
example *ip = *ip + 10; and x = x + 10; are equivalent
The * and & operators bind more tightly than arithmetic operators so
y = *ip + 1; takes the value of the variable to which ip points, adds 1
and assigns it to y
Similarly, the statements *ip += 1; and ++*ip; and (*ip)++; all increment
the variable to which ip points. (Note that the parenthesis are
necessary in the last statement; without them, the expression would
increment ip rather than what it points to since operators like * and
++ associate from right to left.)
Pointer and Variable types
• The type of a pointer and its pointee must matchThe type of a pointer and its pointee must match
int a = 42;
int *ip;
double d = 6.34;
double *dp;
ip = &a; /* ok -- types match */
dp = &d; /* ok */
ip = &d; /* compiler error -- type mismatch */
dp = &a; /* compiler error */
More Pointer Code
• Use ampersand (Use ampersand ( & ) to obtain the address of the pointee) to obtain the address of the pointee
• Use star (Use star ( * ) to get / change the value of the pointee) to get / change the value of the pointee
• UseUse %p to print the value of a pointer withto print the value of a pointer with printf( )
• What is the output from this code?What is the output from this code?
int a = 1, *ptr1;
/* show value and address of a
** and value of the pointer */
ptr1 = &a ;
printf("a = %d, &a = %p, ptr1 = %p, *ptr1 = %dn",
a, &a, ptr1, *ptr1) ;
/* change the value of a by dereferencing ptr1
** then print again */
*ptr1 = 35 ;
printf(“a = %d, &a = %p, ptr1 = %p, *ptr1 = %dn",
a, &a, ptr1, *ptr1) ;
NULL
• NULL is a special value which may be assigned to a pointerNULL is a special value which may be assigned to a pointer
• NULL indicates that this pointer does not point to any variableNULL indicates that this pointer does not point to any variable
(there is no pointee)(there is no pointee)
• Often used when pointers are declaredOften used when pointers are declared
int *pInt = NULL;
• Often used as the return type of functions that return a pointer toOften used as the return type of functions that return a pointer to
indicate function failureindicate function failure
int *myPtr;
myPtr = myFunction( );
if (myPtr == NULL){
/* something bad happened */
}
• Dereferencing a pointer whose value is NULL will result inDereferencing a pointer whose value is NULL will result in
program terminationprogram termination..
Pointers and Function Arguments
• Since C passes all primitive function arguments “by value” thereSince C passes all primitive function arguments “by value” there
is no direct way for a function to alter a variable in the callingis no direct way for a function to alter a variable in the calling
code.code.
• This version of theThis version of the swap function doesn’t work.function doesn’t work. WHY NOT?WHY NOT?
/* calling swap from somewhere in main() */
int x = 42, y = 17;
Swap( x, y );
/* wrong version of swap */
void Swap (int a, int b)
{
int temp;
temp = a;
a = b;
b = temp;
}
A better swap( )
• The desired effect can be obtained by passing pointers to theThe desired effect can be obtained by passing pointers to the
values to be exchanged.values to be exchanged.
• This is a very common use of pointers.This is a very common use of pointers.
/* calling swap from somewhere in main( ) */
int x = 42, y = 17;
Swap( &x, &y );
/* correct version of swap */
void Swap (int *px, int *py)
{
int temp;
temp = *px;
*px = *py;
*py = temp;
}
More Pointer Function
Parameters
• Passing the address of variable(s) to a function canPassing the address of variable(s) to a function can
be used to have a function “return” multiple values.be used to have a function “return” multiple values.
• The pointer arguments point to variables in the callingThe pointer arguments point to variables in the calling
code which are changed (“returned”) by the function.code which are changed (“returned”) by the function.
ConvertTime.c
void ConvertTime (int time, int *pHours, int *pMins)
{
*pHours = time / 60;
*pMins = time % 60;
}
int main( )
{
int time, hours, minutes;
printf("Enter a time duration in minutes: ");
scanf ("%d", &time);
ConvertTime (time, &hours, &minutes);
printf("HH:MM format: %d:%02dn", hours, minutes);
return 0;
}
An Exercise
• What is the output from this code?What is the output from this code?
void F (int a, int *b)
{
a = 7 ;
*b = a ;
b = &a ;
*b = 4 ;
printf("%d, %dn", a, *b) ;
}
int main()
{
int m = 3, n = 5;
F(m, &n) ;
printf("%d, %dn", m, n) ;
return 0;
}
4, 4
3, 7
Pointers to struct
/* define a struct for related student data */
typedef struct student {
char name[50];
char major [20];
double gpa;
} STUDENT;
STUDENT bob = {"Bob Smith", "Math", 3.77};
STUDENT sally = {"Sally", "CSEE", 4.0};
STUDENT *pStudent; /* pStudent is a "pointer to struct student" */
/* make pStudent point to bob */
pStudent = &bob;
/* use -> to access the members */
printf ("Bob's name: %sn", pStudent->name);
printf ("Bob's gpa : %fn", pStudent->gpa);
/* make pStudent point to sally */
pStudent = &sally;
printf ("Sally's name: %sn", pStudent->name);
printf ("Sally's gpa: %fn", pStudent->gpa);
Note too that the following are equivalent. Why??
pStudent->gpa and (*pStudent).gpa /* the parentheses are necessary */
Pointer to struct for functions
void PrintStudent(STUDENT *studentp)
{
printf(“Name : %sn”, studentp->name);
printf(“Major: %sn”, studentp->major);
printf(“GPA : %4.2f”, studentp->gpa);
}
Passing a pointer to a struct to a function is more
efficient than passing the struct itself. Why is this
true?
References
1. www.tutorialspoint.com/cprogramming/c_pointers.htm
2. www.cprogramming.com/tutorial/c/lesson6.html
3. pw1.netcom.com/~tjensen/ptr/pointers.html
4. Programming in C by yashwant kanitkar
5.ANSI C by E.balagurusamy- TMG publication
6.Computer programming and Utilization by sanjay shah Mahajan Publication
7.www.cprogramming.com/books.html
8.en.wikipedia.org/wiki/C_(programming_language)

Más contenido relacionado

La actualidad más candente (19)

Practical Meta Programming
Practical Meta ProgrammingPractical Meta Programming
Practical Meta Programming
 
Pointer in C
Pointer in CPointer in C
Pointer in C
 
Pointers in c
Pointers in cPointers in c
Pointers in c
 
C programming - Pointer and DMA
C programming - Pointer and DMAC programming - Pointer and DMA
C programming - Pointer and DMA
 
Pointers in C
Pointers in CPointers in C
Pointers in C
 
Ponters
PontersPonters
Ponters
 
Pointer in c
Pointer in cPointer in c
Pointer in c
 
Introduction to pointers and memory management in C
Introduction to pointers and memory management in CIntroduction to pointers and memory management in C
Introduction to pointers and memory management in C
 
C pointer
C pointerC pointer
C pointer
 
Dynamic Memory Allocation in C
Dynamic Memory Allocation in CDynamic Memory Allocation in C
Dynamic Memory Allocation in C
 
Types of pointer in C
Types of pointer in CTypes of pointer in C
Types of pointer in C
 
Pointers in C Programming
Pointers in C ProgrammingPointers in C Programming
Pointers in C Programming
 
Advance topics of C language
Advance  topics of C languageAdvance  topics of C language
Advance topics of C language
 
Pointers (Pp Tminimizer)
Pointers (Pp Tminimizer)Pointers (Pp Tminimizer)
Pointers (Pp Tminimizer)
 
Pointers in c - Mohammad Salman
Pointers in c - Mohammad SalmanPointers in c - Mohammad Salman
Pointers in c - Mohammad Salman
 
Pointer in c program
Pointer in c programPointer in c program
Pointer in c program
 
Pointers
PointersPointers
Pointers
 
Advanced C programming
Advanced C programmingAdvanced C programming
Advanced C programming
 
C pointers
C pointersC pointers
C pointers
 

Destacado

Amy Kenton - The Gardner Theory of Multiple Intelligences
Amy Kenton - The Gardner Theory of Multiple IntelligencesAmy Kenton - The Gardner Theory of Multiple Intelligences
Amy Kenton - The Gardner Theory of Multiple IntelligencesAmy Kenton
 
The Groundbreaking Work of Educator Howard Gardner
The Groundbreaking Work of Educator Howard GardnerThe Groundbreaking Work of Educator Howard Gardner
The Groundbreaking Work of Educator Howard GardnerAmy Kenton
 
Academic, Cultural, Sports, Social, Clubs at Rai University, Ahmedabad-INDIA
Academic, Cultural, Sports, Social, Clubs at Rai University, Ahmedabad-INDIAAcademic, Cultural, Sports, Social, Clubs at Rai University, Ahmedabad-INDIA
Academic, Cultural, Sports, Social, Clubs at Rai University, Ahmedabad-INDIARai University
 
The Truth about Electric Vehicles (EVs) in Hot Weather
The Truth about Electric Vehicles (EVs) in Hot WeatherThe Truth about Electric Vehicles (EVs) in Hot Weather
The Truth about Electric Vehicles (EVs) in Hot WeatherFleetCarma
 
How to Win Educational Grants
How to Win Educational GrantsHow to Win Educational Grants
How to Win Educational GrantsAmy Kenton
 
Amy Kenton - The Charlotte Danielson Framework
Amy Kenton - The Charlotte Danielson Framework Amy Kenton - The Charlotte Danielson Framework
Amy Kenton - The Charlotte Danielson Framework Amy Kenton
 
B.sc cs-ii-u-2.1-overview of register transfer, micro operations and basic co...
B.sc cs-ii-u-2.1-overview of register transfer, micro operations and basic co...B.sc cs-ii-u-2.1-overview of register transfer, micro operations and basic co...
B.sc cs-ii-u-2.1-overview of register transfer, micro operations and basic co...Rai University
 
B.tech. ii engineering chemistry unit 3 D plastics
B.tech. ii engineering chemistry unit 3 D plasticsB.tech. ii engineering chemistry unit 3 D plastics
B.tech. ii engineering chemistry unit 3 D plasticsRai University
 
B sc micro, biotech, biochem i es u 3.1 ecosystem
B sc micro, biotech, biochem i es u 3.1 ecosystemB sc micro, biotech, biochem i es u 3.1 ecosystem
B sc micro, biotech, biochem i es u 3.1 ecosystemRai University
 
Rai University, Ahmedabad (Gujarat) - Campus Rider Web Newsletter 2014
Rai University, Ahmedabad (Gujarat) - Campus Rider Web Newsletter 2014Rai University, Ahmedabad (Gujarat) - Campus Rider Web Newsletter 2014
Rai University, Ahmedabad (Gujarat) - Campus Rider Web Newsletter 2014Rai University
 
Smart Charging & the ChargeTO Pilot Slides from Webinar
Smart Charging & the ChargeTO Pilot Slides from WebinarSmart Charging & the ChargeTO Pilot Slides from Webinar
Smart Charging & the ChargeTO Pilot Slides from WebinarFleetCarma
 
The Truth About Electric Vehicles in Cold Weather
The Truth About Electric Vehicles in Cold WeatherThe Truth About Electric Vehicles in Cold Weather
The Truth About Electric Vehicles in Cold WeatherFleetCarma
 
Maximizing the ROI of Fleet Electrification
Maximizing the ROI of Fleet ElectrificationMaximizing the ROI of Fleet Electrification
Maximizing the ROI of Fleet ElectrificationFleetCarma
 
Bba ii cam u iii-introduction to sdlc cycle
Bba ii cam  u iii-introduction to sdlc cycleBba ii cam  u iii-introduction to sdlc cycle
Bba ii cam u iii-introduction to sdlc cycleRai University
 
Mca i-u-4 central processing unit and pipeline
Mca i-u-4 central processing unit and pipelineMca i-u-4 central processing unit and pipeline
Mca i-u-4 central processing unit and pipelineRai University
 
B.tech i ecls_u-1.3_degree of comparison
B.tech i ecls_u-1.3_degree of comparisonB.tech i ecls_u-1.3_degree of comparison
B.tech i ecls_u-1.3_degree of comparisonRai University
 

Destacado (20)

Dovanojimas
DovanojimasDovanojimas
Dovanojimas
 
Amy Kenton - The Gardner Theory of Multiple Intelligences
Amy Kenton - The Gardner Theory of Multiple IntelligencesAmy Kenton - The Gardner Theory of Multiple Intelligences
Amy Kenton - The Gardner Theory of Multiple Intelligences
 
The Groundbreaking Work of Educator Howard Gardner
The Groundbreaking Work of Educator Howard GardnerThe Groundbreaking Work of Educator Howard Gardner
The Groundbreaking Work of Educator Howard Gardner
 
Academic, Cultural, Sports, Social, Clubs at Rai University, Ahmedabad-INDIA
Academic, Cultural, Sports, Social, Clubs at Rai University, Ahmedabad-INDIAAcademic, Cultural, Sports, Social, Clubs at Rai University, Ahmedabad-INDIA
Academic, Cultural, Sports, Social, Clubs at Rai University, Ahmedabad-INDIA
 
The Truth about Electric Vehicles (EVs) in Hot Weather
The Truth about Electric Vehicles (EVs) in Hot WeatherThe Truth about Electric Vehicles (EVs) in Hot Weather
The Truth about Electric Vehicles (EVs) in Hot Weather
 
Valentino diena
Valentino dienaValentino diena
Valentino diena
 
How to Win Educational Grants
How to Win Educational GrantsHow to Win Educational Grants
How to Win Educational Grants
 
Amy Kenton - The Charlotte Danielson Framework
Amy Kenton - The Charlotte Danielson Framework Amy Kenton - The Charlotte Danielson Framework
Amy Kenton - The Charlotte Danielson Framework
 
B.sc cs-ii-u-2.1-overview of register transfer, micro operations and basic co...
B.sc cs-ii-u-2.1-overview of register transfer, micro operations and basic co...B.sc cs-ii-u-2.1-overview of register transfer, micro operations and basic co...
B.sc cs-ii-u-2.1-overview of register transfer, micro operations and basic co...
 
B.tech. ii engineering chemistry unit 3 D plastics
B.tech. ii engineering chemistry unit 3 D plasticsB.tech. ii engineering chemistry unit 3 D plastics
B.tech. ii engineering chemistry unit 3 D plastics
 
Aguonos
AguonosAguonos
Aguonos
 
B sc micro, biotech, biochem i es u 3.1 ecosystem
B sc micro, biotech, biochem i es u 3.1 ecosystemB sc micro, biotech, biochem i es u 3.1 ecosystem
B sc micro, biotech, biochem i es u 3.1 ecosystem
 
Rai University, Ahmedabad (Gujarat) - Campus Rider Web Newsletter 2014
Rai University, Ahmedabad (Gujarat) - Campus Rider Web Newsletter 2014Rai University, Ahmedabad (Gujarat) - Campus Rider Web Newsletter 2014
Rai University, Ahmedabad (Gujarat) - Campus Rider Web Newsletter 2014
 
Smart Charging & the ChargeTO Pilot Slides from Webinar
Smart Charging & the ChargeTO Pilot Slides from WebinarSmart Charging & the ChargeTO Pilot Slides from Webinar
Smart Charging & the ChargeTO Pilot Slides from Webinar
 
Nenusimink2
Nenusimink2Nenusimink2
Nenusimink2
 
The Truth About Electric Vehicles in Cold Weather
The Truth About Electric Vehicles in Cold WeatherThe Truth About Electric Vehicles in Cold Weather
The Truth About Electric Vehicles in Cold Weather
 
Maximizing the ROI of Fleet Electrification
Maximizing the ROI of Fleet ElectrificationMaximizing the ROI of Fleet Electrification
Maximizing the ROI of Fleet Electrification
 
Bba ii cam u iii-introduction to sdlc cycle
Bba ii cam  u iii-introduction to sdlc cycleBba ii cam  u iii-introduction to sdlc cycle
Bba ii cam u iii-introduction to sdlc cycle
 
Mca i-u-4 central processing unit and pipeline
Mca i-u-4 central processing unit and pipelineMca i-u-4 central processing unit and pipeline
Mca i-u-4 central processing unit and pipeline
 
B.tech i ecls_u-1.3_degree of comparison
B.tech i ecls_u-1.3_degree of comparisonB.tech i ecls_u-1.3_degree of comparison
B.tech i ecls_u-1.3_degree of comparison
 

Similar a pointer, structure ,union and intro to file handling

btech-1picu-5pointerstructureunionandintrotofilehandling-150122010700-conver.ppt
btech-1picu-5pointerstructureunionandintrotofilehandling-150122010700-conver.pptbtech-1picu-5pointerstructureunionandintrotofilehandling-150122010700-conver.ppt
btech-1picu-5pointerstructureunionandintrotofilehandling-150122010700-conver.pptchintuyadav19
 
Pointers-Computer programming
Pointers-Computer programmingPointers-Computer programming
Pointers-Computer programmingnmahi96
 
358 33 powerpoint-slides_3-pointers_chapter-3
358 33 powerpoint-slides_3-pointers_chapter-3358 33 powerpoint-slides_3-pointers_chapter-3
358 33 powerpoint-slides_3-pointers_chapter-3sumitbardhan
 
FYBSC(CS)_UNIT-1_Pointers in C.pptx
FYBSC(CS)_UNIT-1_Pointers in C.pptxFYBSC(CS)_UNIT-1_Pointers in C.pptx
FYBSC(CS)_UNIT-1_Pointers in C.pptxsangeeta borde
 
EASY UNDERSTANDING OF POINTERS IN C LANGUAGE.pdf
EASY UNDERSTANDING OF POINTERS IN C LANGUAGE.pdfEASY UNDERSTANDING OF POINTERS IN C LANGUAGE.pdf
EASY UNDERSTANDING OF POINTERS IN C LANGUAGE.pdfsudhakargeruganti
 
Mca ii dfs u-2 array records and pointer
Mca ii dfs u-2 array records and pointerMca ii dfs u-2 array records and pointer
Mca ii dfs u-2 array records and pointerRai University
 
Pointers and Array, pointer and String.pptx
Pointers and Array, pointer and String.pptxPointers and Array, pointer and String.pptx
Pointers and Array, pointer and String.pptxAnanthi Palanisamy
 
Pointers in C Language
Pointers in C LanguagePointers in C Language
Pointers in C Languagemadan reddy
 
VIT351 Software Development VI Unit3
VIT351 Software Development VI Unit3VIT351 Software Development VI Unit3
VIT351 Software Development VI Unit3YOGESH SINGH
 

Similar a pointer, structure ,union and intro to file handling (20)

btech-1picu-5pointerstructureunionandintrotofilehandling-150122010700-conver.ppt
btech-1picu-5pointerstructureunionandintrotofilehandling-150122010700-conver.pptbtech-1picu-5pointerstructureunionandintrotofilehandling-150122010700-conver.ppt
btech-1picu-5pointerstructureunionandintrotofilehandling-150122010700-conver.ppt
 
pointers.pptx
pointers.pptxpointers.pptx
pointers.pptx
 
Pointers-Computer programming
Pointers-Computer programmingPointers-Computer programming
Pointers-Computer programming
 
358 33 powerpoint-slides_3-pointers_chapter-3
358 33 powerpoint-slides_3-pointers_chapter-3358 33 powerpoint-slides_3-pointers_chapter-3
358 33 powerpoint-slides_3-pointers_chapter-3
 
Pointers
PointersPointers
Pointers
 
Pointer.pptx
Pointer.pptxPointer.pptx
Pointer.pptx
 
Session 5
Session 5Session 5
Session 5
 
FYBSC(CS)_UNIT-1_Pointers in C.pptx
FYBSC(CS)_UNIT-1_Pointers in C.pptxFYBSC(CS)_UNIT-1_Pointers in C.pptx
FYBSC(CS)_UNIT-1_Pointers in C.pptx
 
PSPC--UNIT-5.pdf
PSPC--UNIT-5.pdfPSPC--UNIT-5.pdf
PSPC--UNIT-5.pdf
 
ch08.ppt
ch08.pptch08.ppt
ch08.ppt
 
C programming session8
C programming  session8C programming  session8
C programming session8
 
C programming session8
C programming  session8C programming  session8
C programming session8
 
EASY UNDERSTANDING OF POINTERS IN C LANGUAGE.pdf
EASY UNDERSTANDING OF POINTERS IN C LANGUAGE.pdfEASY UNDERSTANDING OF POINTERS IN C LANGUAGE.pdf
EASY UNDERSTANDING OF POINTERS IN C LANGUAGE.pdf
 
Mca ii dfs u-2 array records and pointer
Mca ii dfs u-2 array records and pointerMca ii dfs u-2 array records and pointer
Mca ii dfs u-2 array records and pointer
 
4 Pointers.pptx
4 Pointers.pptx4 Pointers.pptx
4 Pointers.pptx
 
Pointer in C
Pointer in CPointer in C
Pointer in C
 
pointers (1).ppt
pointers (1).pptpointers (1).ppt
pointers (1).ppt
 
Pointers and Array, pointer and String.pptx
Pointers and Array, pointer and String.pptxPointers and Array, pointer and String.pptx
Pointers and Array, pointer and String.pptx
 
Pointers in C Language
Pointers in C LanguagePointers in C Language
Pointers in C Language
 
VIT351 Software Development VI Unit3
VIT351 Software Development VI Unit3VIT351 Software Development VI Unit3
VIT351 Software Development VI Unit3
 

Más de Rai University

Brochure Rai University
Brochure Rai University Brochure Rai University
Brochure Rai University Rai University
 
Bdft ii, tmt, unit-iii, dyeing & types of dyeing,
Bdft ii, tmt, unit-iii,  dyeing & types of dyeing,Bdft ii, tmt, unit-iii,  dyeing & types of dyeing,
Bdft ii, tmt, unit-iii, dyeing & types of dyeing,Rai University
 
Bsc agri 2 pae u-4.4 publicrevenue-presentation-130208082149-phpapp02
Bsc agri  2 pae  u-4.4 publicrevenue-presentation-130208082149-phpapp02Bsc agri  2 pae  u-4.4 publicrevenue-presentation-130208082149-phpapp02
Bsc agri 2 pae u-4.4 publicrevenue-presentation-130208082149-phpapp02Rai University
 
Bsc agri 2 pae u-4.3 public expenditure
Bsc agri  2 pae  u-4.3 public expenditureBsc agri  2 pae  u-4.3 public expenditure
Bsc agri 2 pae u-4.3 public expenditureRai University
 
Bsc agri 2 pae u-4.2 public finance
Bsc agri  2 pae  u-4.2 public financeBsc agri  2 pae  u-4.2 public finance
Bsc agri 2 pae u-4.2 public financeRai University
 
Bsc agri 2 pae u-4.1 introduction
Bsc agri  2 pae  u-4.1 introductionBsc agri  2 pae  u-4.1 introduction
Bsc agri 2 pae u-4.1 introductionRai University
 
Bsc agri 2 pae u-3.3 inflation
Bsc agri  2 pae  u-3.3  inflationBsc agri  2 pae  u-3.3  inflation
Bsc agri 2 pae u-3.3 inflationRai University
 
Bsc agri 2 pae u-3.2 introduction to macro economics
Bsc agri  2 pae  u-3.2 introduction to macro economicsBsc agri  2 pae  u-3.2 introduction to macro economics
Bsc agri 2 pae u-3.2 introduction to macro economicsRai University
 
Bsc agri 2 pae u-3.1 marketstructure
Bsc agri  2 pae  u-3.1 marketstructureBsc agri  2 pae  u-3.1 marketstructure
Bsc agri 2 pae u-3.1 marketstructureRai University
 
Bsc agri 2 pae u-3 perfect-competition
Bsc agri  2 pae  u-3 perfect-competitionBsc agri  2 pae  u-3 perfect-competition
Bsc agri 2 pae u-3 perfect-competitionRai University
 

Más de Rai University (20)

Brochure Rai University
Brochure Rai University Brochure Rai University
Brochure Rai University
 
Mm unit 4point2
Mm unit 4point2Mm unit 4point2
Mm unit 4point2
 
Mm unit 4point1
Mm unit 4point1Mm unit 4point1
Mm unit 4point1
 
Mm unit 4point3
Mm unit 4point3Mm unit 4point3
Mm unit 4point3
 
Mm unit 3point2
Mm unit 3point2Mm unit 3point2
Mm unit 3point2
 
Mm unit 3point1
Mm unit 3point1Mm unit 3point1
Mm unit 3point1
 
Mm unit 2point2
Mm unit 2point2Mm unit 2point2
Mm unit 2point2
 
Mm unit 2 point 1
Mm unit 2 point 1Mm unit 2 point 1
Mm unit 2 point 1
 
Mm unit 1point3
Mm unit 1point3Mm unit 1point3
Mm unit 1point3
 
Mm unit 1point2
Mm unit 1point2Mm unit 1point2
Mm unit 1point2
 
Mm unit 1point1
Mm unit 1point1Mm unit 1point1
Mm unit 1point1
 
Bdft ii, tmt, unit-iii, dyeing & types of dyeing,
Bdft ii, tmt, unit-iii,  dyeing & types of dyeing,Bdft ii, tmt, unit-iii,  dyeing & types of dyeing,
Bdft ii, tmt, unit-iii, dyeing & types of dyeing,
 
Bsc agri 2 pae u-4.4 publicrevenue-presentation-130208082149-phpapp02
Bsc agri  2 pae  u-4.4 publicrevenue-presentation-130208082149-phpapp02Bsc agri  2 pae  u-4.4 publicrevenue-presentation-130208082149-phpapp02
Bsc agri 2 pae u-4.4 publicrevenue-presentation-130208082149-phpapp02
 
Bsc agri 2 pae u-4.3 public expenditure
Bsc agri  2 pae  u-4.3 public expenditureBsc agri  2 pae  u-4.3 public expenditure
Bsc agri 2 pae u-4.3 public expenditure
 
Bsc agri 2 pae u-4.2 public finance
Bsc agri  2 pae  u-4.2 public financeBsc agri  2 pae  u-4.2 public finance
Bsc agri 2 pae u-4.2 public finance
 
Bsc agri 2 pae u-4.1 introduction
Bsc agri  2 pae  u-4.1 introductionBsc agri  2 pae  u-4.1 introduction
Bsc agri 2 pae u-4.1 introduction
 
Bsc agri 2 pae u-3.3 inflation
Bsc agri  2 pae  u-3.3  inflationBsc agri  2 pae  u-3.3  inflation
Bsc agri 2 pae u-3.3 inflation
 
Bsc agri 2 pae u-3.2 introduction to macro economics
Bsc agri  2 pae  u-3.2 introduction to macro economicsBsc agri  2 pae  u-3.2 introduction to macro economics
Bsc agri 2 pae u-3.2 introduction to macro economics
 
Bsc agri 2 pae u-3.1 marketstructure
Bsc agri  2 pae  u-3.1 marketstructureBsc agri  2 pae  u-3.1 marketstructure
Bsc agri 2 pae u-3.1 marketstructure
 
Bsc agri 2 pae u-3 perfect-competition
Bsc agri  2 pae  u-3 perfect-competitionBsc agri  2 pae  u-3 perfect-competition
Bsc agri 2 pae u-3 perfect-competition
 

Último

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
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
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
 
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...KokoStevan
 
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
 
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
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfSanaAli374401
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 

Último (20)

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
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
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
 
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
 
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
 
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...
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 

pointer, structure ,union and intro to file handling

  • 1. Unit-5 Pointer, Structure, Union & Intro to File Handling Course: BCA Subject: Programming In C Language
  • 2. What is a pointer • In a generic sense, a “pointer” is anything that tells usIn a generic sense, a “pointer” is anything that tells us where something can be found.where something can be found. – Addresses in the phone book – URLs for webpages – Road signs
  • 3. Java Reference • In Java, the name of an object is a reference to that object.In Java, the name of an object is a reference to that object. HereHere ford is a reference to a Truck object. It contains theis a reference to a Truck object. It contains the memory address at which the Truck object is stored.memory address at which the Truck object is stored. Truck ford = new Truck( ); • The syntax for using the reference is pretty simple. JustThe syntax for using the reference is pretty simple. Just use the “dot” notation.use the “dot” notation. ford.start( ); ford.drive( 23 ); ford.turn (LEFT);
  • 4. What is a pointer ? • In C, a pointer variable (or just “pointer”) is similar toIn C, a pointer variable (or just “pointer”) is similar to a reference in Java except thata reference in Java except that – A pointer can contain the memory address of any variable type (Java references only refer to objects) – A primitive (int, char, float) – An array – A struct or union – Dynamically allocated memory – Another pointer – A function – There’s a lot of syntax required to create and use pointers
  • 5. Why Pointers? • They allow you to refer to large data structures in a compactThey allow you to refer to large data structures in a compact wayway • They facilitate sharing between different parts of programsThey facilitate sharing between different parts of programs • They make it possible to get new memory dynamically as yourThey make it possible to get new memory dynamically as your program is runningprogram is running • They make it easy to represent relationships among data items.They make it easy to represent relationships among data items.
  • 6. Pointer Caution • They are a powerful low-level device.They are a powerful low-level device. • Undisciplined use can be confusing and thus theUndisciplined use can be confusing and thus the source of subtle, hard-to-find bugs.source of subtle, hard-to-find bugs. – Program crashes – Memory leaks – Unpredictable results
  • 7. C Pointer Variables To declare a pointer variable, we must do two thingsTo declare a pointer variable, we must do two things – Use the “*” (star) character to indicate that the variable being defined is a pointer type. – Indicate the type of variable to which the pointer will point (the pointee). This is necessary because C provides operations on pointers (e.g., *, ++, etc) whose meaning depends on the type of the pointee. • General declaration of a pointerGeneral declaration of a pointer type *nameOfPointer;
  • 8. Pointer Declaration The declarationThe declaration int *intPtr; defines the variabledefines the variable intPtr to be a pointer to a variable of typeto be a pointer to a variable of type int.. intPtr will contain the memory address of somewill contain the memory address of some int variable orvariable or int array. Read this declaration asarray. Read this declaration as – “intPtr is a pointer to an int”, or equivalently – “*intPtr is an int” Caution -- Be careful when defining multiple variables on the sameCaution -- Be careful when defining multiple variables on the same line. In this definitionline. In this definition int *intPtr, intPtr2; intPtr is a pointer to an int, but intPtr2 is not!
  • 9. Pointer Operators The two primary operators used with pointers areThe two primary operators used with pointers are * (star) and(star) and && (ampersand)(ampersand) – The * operator is used to define pointer variables and to deference a pointer. “Dereferencing” a pointer means to use the value of the pointee. – The & operator gives the address of a variable. Recall the use of & in scanf( )
  • 10. Pointer Examples int x = 1, y = 2, z[10]; int *ip; /* ip is a pointer to an int */ ip = &x; /* ip points to (contains the memory address of) x */ y = *ip; /* y is now 1, indirectly copied from x using ip */ *ip = 0; /* x is now 0 */ ip = &z[5]; /* ip now points to z[5] */ If ip points to x, then *ip can be used anywhere x can be used so in this example *ip = *ip + 10; and x = x + 10; are equivalent The * and & operators bind more tightly than arithmetic operators so y = *ip + 1; takes the value of the variable to which ip points, adds 1 and assigns it to y Similarly, the statements *ip += 1; and ++*ip; and (*ip)++; all increment the variable to which ip points. (Note that the parenthesis are necessary in the last statement; without them, the expression would increment ip rather than what it points to since operators like * and ++ associate from right to left.)
  • 11. Pointer and Variable types • The type of a pointer and its pointee must matchThe type of a pointer and its pointee must match int a = 42; int *ip; double d = 6.34; double *dp; ip = &a; /* ok -- types match */ dp = &d; /* ok */ ip = &d; /* compiler error -- type mismatch */ dp = &a; /* compiler error */
  • 12. More Pointer Code • Use ampersand (Use ampersand ( & ) to obtain the address of the pointee) to obtain the address of the pointee • Use star (Use star ( * ) to get / change the value of the pointee) to get / change the value of the pointee • UseUse %p to print the value of a pointer withto print the value of a pointer with printf( ) • What is the output from this code?What is the output from this code? int a = 1, *ptr1; /* show value and address of a ** and value of the pointer */ ptr1 = &a ; printf("a = %d, &a = %p, ptr1 = %p, *ptr1 = %dn", a, &a, ptr1, *ptr1) ; /* change the value of a by dereferencing ptr1 ** then print again */ *ptr1 = 35 ; printf(“a = %d, &a = %p, ptr1 = %p, *ptr1 = %dn", a, &a, ptr1, *ptr1) ;
  • 13. NULL • NULL is a special value which may be assigned to a pointerNULL is a special value which may be assigned to a pointer • NULL indicates that this pointer does not point to any variableNULL indicates that this pointer does not point to any variable (there is no pointee)(there is no pointee) • Often used when pointers are declaredOften used when pointers are declared int *pInt = NULL; • Often used as the return type of functions that return a pointer toOften used as the return type of functions that return a pointer to indicate function failureindicate function failure int *myPtr; myPtr = myFunction( ); if (myPtr == NULL){ /* something bad happened */ } • Dereferencing a pointer whose value is NULL will result inDereferencing a pointer whose value is NULL will result in program terminationprogram termination..
  • 14. Pointers and Function Arguments • Since C passes all primitive function arguments “by value” thereSince C passes all primitive function arguments “by value” there is no direct way for a function to alter a variable in the callingis no direct way for a function to alter a variable in the calling code.code. • This version of theThis version of the swap function doesn’t work.function doesn’t work. WHY NOT?WHY NOT? /* calling swap from somewhere in main() */ int x = 42, y = 17; Swap( x, y ); /* wrong version of swap */ void Swap (int a, int b) { int temp; temp = a; a = b; b = temp; }
  • 15. A better swap( ) • The desired effect can be obtained by passing pointers to theThe desired effect can be obtained by passing pointers to the values to be exchanged.values to be exchanged. • This is a very common use of pointers.This is a very common use of pointers. /* calling swap from somewhere in main( ) */ int x = 42, y = 17; Swap( &x, &y ); /* correct version of swap */ void Swap (int *px, int *py) { int temp; temp = *px; *px = *py; *py = temp; }
  • 16. More Pointer Function Parameters • Passing the address of variable(s) to a function canPassing the address of variable(s) to a function can be used to have a function “return” multiple values.be used to have a function “return” multiple values. • The pointer arguments point to variables in the callingThe pointer arguments point to variables in the calling code which are changed (“returned”) by the function.code which are changed (“returned”) by the function.
  • 17. ConvertTime.c void ConvertTime (int time, int *pHours, int *pMins) { *pHours = time / 60; *pMins = time % 60; } int main( ) { int time, hours, minutes; printf("Enter a time duration in minutes: "); scanf ("%d", &time); ConvertTime (time, &hours, &minutes); printf("HH:MM format: %d:%02dn", hours, minutes); return 0; }
  • 18. An Exercise • What is the output from this code?What is the output from this code? void F (int a, int *b) { a = 7 ; *b = a ; b = &a ; *b = 4 ; printf("%d, %dn", a, *b) ; } int main() { int m = 3, n = 5; F(m, &n) ; printf("%d, %dn", m, n) ; return 0; } 4, 4 3, 7
  • 19. Pointers to struct /* define a struct for related student data */ typedef struct student { char name[50]; char major [20]; double gpa; } STUDENT; STUDENT bob = {"Bob Smith", "Math", 3.77}; STUDENT sally = {"Sally", "CSEE", 4.0}; STUDENT *pStudent; /* pStudent is a "pointer to struct student" */ /* make pStudent point to bob */ pStudent = &bob; /* use -> to access the members */ printf ("Bob's name: %sn", pStudent->name); printf ("Bob's gpa : %fn", pStudent->gpa); /* make pStudent point to sally */ pStudent = &sally; printf ("Sally's name: %sn", pStudent->name); printf ("Sally's gpa: %fn", pStudent->gpa); Note too that the following are equivalent. Why?? pStudent->gpa and (*pStudent).gpa /* the parentheses are necessary */
  • 20. Pointer to struct for functions void PrintStudent(STUDENT *studentp) { printf(“Name : %sn”, studentp->name); printf(“Major: %sn”, studentp->major); printf(“GPA : %4.2f”, studentp->gpa); } Passing a pointer to a struct to a function is more efficient than passing the struct itself. Why is this true?
  • 21. References 1. www.tutorialspoint.com/cprogramming/c_pointers.htm 2. www.cprogramming.com/tutorial/c/lesson6.html 3. pw1.netcom.com/~tjensen/ptr/pointers.html 4. Programming in C by yashwant kanitkar 5.ANSI C by E.balagurusamy- TMG publication 6.Computer programming and Utilization by sanjay shah Mahajan Publication 7.www.cprogramming.com/books.html 8.en.wikipedia.org/wiki/C_(programming_language)