Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Save to My Library
Look up keyword
Like this
2Activity
0 of .
Results for:
No results containing your search query
P. 1
Cse Assignment 4 fully solved

Cse Assignment 4 fully solved

Ratings: (0)|Views: 76 |Likes:
Published by Rana Vivek Singh

More info:

Categories:Topics, Art & Design
Published by: Rana Vivek Singh on Nov 20, 2010
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as DOC, PDF, TXT or read online from Scribd
See more
See less

07/01/2012

pdf

text

original

 
Lovely Professional University
 
COMPUTER SCIENCES 
 
ASSIGNMENT 4
Submitted To:- Miss VASUDHA RANCHAL.
 SUBMITTED BY:-
 ANKIT KUMAR PATHAK.
 
ROLL NO.:- RF1003A06
 
REG. NO:- 11005356
 
GROUP:-
 
1
 
SECTION:-
 
F1003
 
 
Q.1) How can you relate the function with structure ? Explain with an appropriate example.
Ans: - A function is a self contained block of statements enclosed between braces that performs a specific task.A structure is a collection of heterogenous elements which are related to one another.Two ways of passing structure to a function:-Pass by value - individual members are passed to function.Pass by reference :- entire structure is passed by use of pointer variable.Individual members of a structure can be passed to a function as argument in the function call. This method of passingindividual member is same as that of passing variable of any primitive type. A complete structure can also be passed to afunction. As structure members are stored in contiguous memory locations . While passing entire structure to a function wedo not have anything like length of the structure like in arrays.Example:-#include<stdio.h>#include<conio.h>void main(){struct address{char phone[15];char city[25];int pin;};struct emp{char name[25];struct address a;};struct emp e={“jasmeen”,”9217706769”,”Nagaland”,13};printf(“\n name=%s phone=%s,e.name,e.a.phone);printf(“\n city =%s pin =%d”,e.a.city,e.a.pin);}
 
 
Q.2) Explain the method of passing a structure by value as an argument to a function with anexample of prototype function declaration , function call.
Ans:- #include<stdio.h>#include<conio.h>#include<string.h>struct record{char name[20];int roll no;float balance;};float funct1(int ,float);void main(){struct record e={“anshu”,12,10.50};clrscr();printf(“\n before call value=%s %d %f”,e.name,e.rollno,e.balance);e.balance= funct1(e.rollno, e.balance);printf(“\n after call value =%s %d %f”,e.name,e.rollno,e.balace);getch();}float funct1(int c, float b){b+=100;c+=10;printf(“\n in function, values=%d %f”,c,b);return(b);}explanation:- In this program , we pass the members roll no and balance of record type variable e to the function funct1() asarguments. This can be seen from the function call.e.balance = func1(e.rollno,e.balance);

You're Reading a Free Preview

Download
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->