Adobe Scan May 13, 2024
Adobe Scan May 13, 2024
314
clements Write sumdigit(int
{ int x) *
ptr
main()
void Function
getch(): printf("n printf("n
for ptr } scanf(%d",
printf("n &A|0clrscr();
printf("n
for &size); }:ptr = *ptr;int int return(s); x%10;d=
st=d+sumigit(x/10); if(x--0)s-0,d;int
size, a return
(i (i in C
size
&A[size1]scanf("%od,
: - ptrt+;ptr); 0;i<
i, program
reverse (0); sum
Element Elements Enter Enter A[30]; of
1;i>s - size; digit
%d the order.using
%od of it+)
integers size define
is i) array0; pointers
%d : of as
in intoarray:");
", reverSe to
Programming in
recursive C
it1, aray:", read
*ptr): order
in */
size); an
are:"):
AprillMay
2015)(AU array
Of
integers
and
print
ie
DEFININGA
STRUCTURE
A10.1.1 There e
nglSructure itemsINTRODUCTION
structure 3. 2. 1. autelotBookExamples: siname. . cture useto An10.1
araray
are The
Acccssing Defining Addressbo is is
Declaring three is collection
individual
may a
convenient a data a
Student collection
parts
be structure
of
structure
objects structure a STRUCTURES UNION
AND
structure
struct
name defined of structure different
one structures: STRUCTURESNTO
of of way
or as, variables type. different whose Structures
Unionand
datatype datatype
memberl;
datatype
moremember n;member2;
structure :name, elements for data
handlng elements
structure author,name, type
type. (i.e. types
objects). are items,
door title, roll referred a are
of
ariables]; data different it all
number.,
no,price, is of
street, items as not the
type
members. possible
year.marks. same
city. that of
are logically todata
stored use type. Chapter10
related an A If
under arTray. we
need 315
data
a
316
Programming in C Structures and Union 317
Nagercoil
Entered Nager
is: Carmel 345 Output:
Sugitha maívoind 0
Sugitha,Address addrstrucetss
address
person;
struct door_number;
street[30]:
city[30]:
char charname[25];
ínt char
getch):
person.street,
person.city): person.street,
person.
printf("\nEntered
Addris:e\nssc);ity): printf("clrscr):
345, 1
Carmel Enter
s,%d,%s,%s\n"spcearnsfo(n"%.nas%md%se,per%sosn",.pdeorsro_n.nnuammbee,&r, person.d_oornumber,
HincluHdein<cloundieo<.hst>dio.h>IlPlrougstramratio101n
Nager, the
Name,door of Unionand
accessingStructures
Nagercoil.
number, structure
members
Street
and
City
name:\n"):
319
Syntax:members using complex STRUCTURES
used structure NESTED10.2 320
Program A
structure
#include<stdio.h>CLRE
dot createto
struct
_data
{stud struct
date ! I of data is
10.2: structdeclarations; struct
declarations;
datatype
struct
the ()
operator,complex
innermost
and called ascan
name[20];
struct
dob; char
date date,month,year;int structure structure
Ilustration structure can placcdbe
helpnested
as inimprove
name2 namel types.
datThea
namel
of conjunction
well structure. within
nested variable as Programming in
C
the
program's aanother
structure outermost elements of Nested
name1; with
the structure. A
rcadability
structurestr
structures
structures.us
nested
39916.02100 variables
accessed
structuresare astructure
nd are
useful
maintainability.
oek
to within
for
accesSS organizng
another
the
10.3 Date of
Syntax: placing self ABirth:6-3-82
symbol When
referenced Here structure Suthan
Name:
Output:
Program10.3
main()
void
#include<stdio.h> referentialPOINTERS
structure
pointers an main()
{void
->
struct
is by asteriskcontaining
called using declarations; s={("Suthan"{06,03,82}}:
printf("\n stud_data
struct
clrscr();
Illustration are name
datatype struct
nametag structure. getch):
s.dob.month,
s.dob.year);
%s"s.name);
printf("\n
Name:
asthe (*) AND
pointing is
structuresymbol in a
a member
frontSTRUCTURES
A
of pointer, \nDate
structure pointer -> to pointer
of Structures
Unionand
a the that
(Hyphen ponting
structure, of
structure
variable is Birth:%d-%d-%d",
using symbol. pointer
a
to
pointers followed then the pointer for
structure the theto
the variable.
by structure same
structure
greater s.dob.date,
specified structure
can
than
elements be
symbol). in type
declared
tag is
canname. called 321
This be by
Programming in C Structures and Union 323
322
TOTAL MARKS
int n o ; o b
student[ 1): 193 bAloatavg:
student|2]: 197
student[3]: 164
void fun(struct std p);
10.5 STRUCTURES AND FUNCTIONS void main(0
n8 s nobule oi
In C there are three methods by which the struct std a;
from one function to another function. They values of a structure can be transfermed t clrscr):
are,
1. Pass each member of the a.no=1;d
2. Pass a copy of the entire
structure as an actual argument of the function. a.avg=90.6;
structure to the called
3. Pass the address
location of the structure to the function.
called function.
fun(a);
getch);
The first method raises a few
when the structure size is large. practical issues like unmanageable and insufficient
void fun(struct std p)
In the second {
method, changes are made only the printf("Number is:%d\n"p.no):
modifications within the function are not reflected in the
copy of the structure. So
printf("Average is: %f\n".p.avg):
Syntax: original structure.
function name(structure_variable name); Output:
datatype function
name(struct_typest name) Number is
Average is
:1
:90.599998