GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Programming  >  C
Go To First  |  Previous Question  |  Next Question 
 C  |  Question 359 of 453    Print  
How is structure passing and returning implemented?

  
Total Answers and Comments: 2 Last Update: July 06, 2009     Asked by: pbchaudhari 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
January 16, 2008 03:59:35   #1  
baseersd Member Since: June 2007   Contribution: 34    

RE: How is structure passing and returning implemented?
Here i am trying to
i)accept input through GetEmployeeDetails()
ii)Print the same details through PrintEmployeeDetails()
iii)Modify / Change the details through ModifyEmployeeDetails()
iv)Print the modified values using PrintEmployeeDetails()


#include<stdio.h>

struct Employee
{
int ID;
char *name;
};
void GetEmployeeDetails(struct Employee *Emp)
{
printf("Enter the ID");
scanf(" d" &Emp->ID);
Emp->name (char*)malloc(20 * sizeof(char));
fflush(stdin);
printf("nEnter the Name");
gets(Emp->name);
}
void PrintEmployeeDetails(struct Employee Emp)
{
printf("nEmployee ID :: d" Emp.ID);
printf("nEmployee Name :: snn" Emp.name);
}

struct Employee* ModifyEmployeeDetails(struct Employee Emp)
{
printf("Enter the ID");
scanf(" d" &Emp.ID);
Emp.name (char*)malloc(20 * sizeof(char));
fflush(stdin);
printf("nEnter the Name");
gets(Emp.name);
return &Emp;
}
int main()
{
struct Employee Emp1 *Emp2;
GetEmployeeDetails(&Emp1);
PrintEmployeeDetails(Emp1);
Emp2 ModifyEmployeeDetails(Emp1);
PrintEmployeeDetails(*Emp2);
system("pause");

}

 
Is this answer useful? Yes | No
July 06, 2009 18:33:40   #2  
abhimanipal Member Since: July 2009   Contribution: 22    

RE: How is structure passing and returning implemented?
Here is my code fragement. It shows passing the structure as argument and returning it as well

#include <stdio.h>
#include <stdlib.h>
#include<math.h>
#include<string.h>

struct abc {
int x;
float x1;
char x2;
};

struct abc check(struct abc a2)
{
printf(" dn" a2.x);
printf(" fn" a2.x1);
printf(" cn" a2.x2);
a2.x 15;
a2.x1 11.14;
a2.x2 'B';
return a2;
}

int main()
{
struct abc a1 a2;
a1.x 10;
a1.x1 5.7;
a1.x2 'A';
a2 check(a1);
printf("n");
printf(" dn" a2.x);
printf(" fn" a2.x1);
printf(" cn" a2.x2);

return 0;
}

 
Is this answer useful? Yes | No

 Related Questions

A goto statement implements a local jump of program execution, and the longjmp() and setjmp() functions implement a nonlocal, or far, jump of program execution. Generally, a jump in execution of any kind 
Latest Answer : using the normal goto statement we can move only within the function. it is not possible to go from one function to another function.using setjmp and longjmp you can move from one function to another function. but it is very bad programming. since the ...

An lvalue was defined as an expression to which a value can be assigned. Is an array an expression to which we can assign a value? The answer to this question is no, because an array is composed of several 
Latest Answer : Array is not an lvalue..Eg.int arr[5] = {"1","2",.......};here arr[5] has  memory address and now we are assinging values to this.if we write arr[5]; in any function then it will not show any error, mean array does required lvalue ...

Yes. The const modifier means that this code cannot change the value of the variable, but that does not mean that the value cannot be changed by means outside this code. For instance, in the example in  
Latest Answer : But isnt like the constant variables will be stored by in ROM (read only memory).Then how can the some process other than the code can change the value of const volatile ...

There are two situations in which to use a type cast. The first use is to change the type of an operand to an arithmetic operation so that the operation will be performed properly.  The second case 
Latest Answer : Type cast should be used in case of if we want to assign a void pointer to a pointer of some data type.eg:void *ptr;int *c;c=(int *)ptr; ...

A type cast should not be used to override a const or volatile declaration. Overriding these type modifiers can cause the program to fail to run correctly. A type cast should not be used to turn a pointer 
Latest Answer : we should not cast the big datatype to smaller one. Like from double to float long to integer. TIn these cases there will be chance of loosing the valuable data itself. ...

The answer depends on what you mean by quickest. For most sorting problems, it just doesn’t matter how quick the sort is because it is done infrequently or other operations take significantly more 
Latest Answer : The algorithms which follows divide and qunquer technique provides fastest implementation. ...

A binary search, such as bsearch() performs, is much faster than a linear search. A hashing algorithm can provide even faster searching. One particularly interesting and fast method for searching is to 
Latest Answer : quick short method is a best one ...

Unfortunately, the only way to search a linked list is with a linear search, because the only way a linked list’s members can be accessed is sequentially. Sometimes it is quicker to take the data 
Latest Answer : hai here am writing a simple ex for searchina linked list for specific valuestruct link{int data;struct link *node;}if the above struct is a node such that in a node u can store a data and pointer to the next node.if u have the pointer the beginning of ...

There are times when it’s necessary to have a pointer that doesn’t point to anything. The macro NULL, defined in , has a value that’s guaranteed to be different from any valid 
Latest Answer : hi,   Null pointer:   When referring to computer memory, a null pointer is a command used to direct a software program or operating system to an empty location in the computer memory. Commonly, the null pointer is used to denote the ...
Tags : Pointer

A void pointer is a C convention for “a raw address.” The compiler has no idea what type of object a void Pointer “really points to.” If you write int *ip; ip points to an int. 
Latest Answer : Void Pointer or Generic Pointer is the one to which any datatype can be assigned.eg.main(){    int *p;     void *vp;     vp=p;} ...
Tags : Pointer


 Sponsored Links

 
Related Articles

Concepts of Object-Oriented Programming

Object Oriented JavaScript In this chapter you ll learn about OOP Object Oriented Programming and how it relates to JavaScript As an ASP NET developer you probably have some experience working with objects and you may even be familiar with concepts such as inheritance However unless you re already a
 

C++ Function Passing Types

C Function Passing Types In this C tutorial you will learn about function passing types two types of arguments passing in functions passed by value&nbsp; and&nbsp; passed by reference are discussed here mosgoogle center The arguments passed to a function can be performed in two ways Passed
 

C++ Structure Part II

C Structure Part II In this C tutorial Structures Part II you will learn how to use structure in an efficient way and features of structures explained with examples mosgoogle center Structure Members Initialization As with arrays and variables structure members can also be initialized This is perfor
 

C++ Structure

C Structure In this C tutorial you will learn about Structure declaring a Structure how to declare Structure Variable and how to access the structure members in C mosgoogle What is a Structure Structure is a collection of variables under a single name Variables can be of any type int float char et
 

What is Common Data Structure

In big data warehouses such as those used by business organizations which may have many branches around the world and which may have diversified products and services, different kinds of data flood the warehouse every single day. These data may come from other warehouse data sources, or simply fresh
 

SQL Programming

SQL Programming Overview Anybody who has done something for a long time has probably wanted to change how things work at some point or another. A worker at a mill might have found a more efficient way of cutting logs, or a mathematics teacher might have had a hand in changing a school&rsquo;s al
 

ITIL Structure

In this article, let us go through some of the aspects involved in the ITIL Structure. Business Perspective The business perspective is meant to familiarize the Business Management with the supporting components and the architectural design of the Information and Technology (ICT), the infrastructure
 

The Interview Snafu

How to turn someone else&rsquo;s mistake to your advantage Your dream job is about to become reality. A recruiter gave you the heads up about the perfect position at Humungous Conglomerate, Inc. You went through five interviews as well as a battery of psychological tests mandated by their HR de
 

Winning a Job Interview with a Winning Resume

Does your resume unlock your potential, take your skills to the highest level and win you the interview and the job you want now? The job market today is highly competitive and even if you think you have what it takes to get an interview you won&rsquo;t get over the line without a polished, prof
 

WinRunner Programming Concepts

If you want to create WinRunner scripts that are highly efficient, there are important programming concepts that you will want to become familiar with. Understanding these concepts will provide you with a large number of key benefits. In addition to understanding these concepts, you must also learn
 

About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape