INTERVIEW QUESTIONS
COMPUTER HARDWARE
EMBEDDED SYSTEMS
DETAILS
Question: Can structures be passed to the functions by value?
Answer: Yes, we can do it. consider the following code.. #include<stdio.h> #include<conio.h> struct emp { int no; int empno; }; typedef struct emp empdata;
main() {
empdata edata; void display( empdata ); clrscr(); edata.no = 1; edata.empno = 2005; display( edata );
return 0; } void display( empdata pst ) { printf( "%d", pst.empno ); }
Submitted by Vijaya Kumar ([email protected])
_______________
Yes structures can be passed to functions by value. Though passing by value has two disadvatanges :
1) The chages by the calling function are not reflected 2) Its slower than the pass by refrence funcion call.
Submitted by Pooja Agrawal ([email protected])
|
Question:
Can structures be passed to the functions by value?
Answer:
Yes, we can do it. consider the following code.. #include<stdio.h> #include<conio.h> struct emp { int no; int empno; }; typedef struct emp empdata;
main() {
empdata edata; void display( empdata ); clrscr(); edata.no = 1; edata.empno = 2005; display( edata );
return 0; } void display( empdata pst ) { printf( "%d", pst.empno ); }
Submitted by Vijaya Kumar ([email protected])
_______________
Yes structures can be passed to functions by value. Though passing by value has two disadvatanges :
1) The chages by the calling function are not reflected 2) Its slower than the pass by refrence funcion call.
Submitted by Pooja Agrawal ([email protected]) Source: CoolInterview.com
The answer is, yes you can, but you shouldnt do it. This is bad programming practice. Think this way, if your structure contains only 4 or 8 bytes, you might get away with it, but for larger structures, if you pass them by value, you are risking stack overflow. Some intelligent code checking softwares will throw you a warning if you pass structures by value. Now the decision is yours!! Cheers Source: CoolInterview.com
Answered by: Abhishek | Date: 4/15/2009
| Contact Abhishek
#include<stdio.h> #include<conio.h> struct empy { int epyno; int batchno; }; void dspy(empy); main() {
empdata edat; clrscr(); edata.no = 1; edata.empno = 2005; display( edat );
return 0; }
void dspy( empy emp ) { printf( "%d", emp.epyno ); }
By Karthik.G (09894149841) Source: CoolInterview.com
Answered by: Karthik | Date: 5/12/2010
| Contact Karthik
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|