GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Programming  >  C
Go To First  |  Previous Question  |  Next Question 
 C  |  Question 401 of 453    Print  
C Structures
Is structure a value type or a reference type? why?


  
Total Answers and Comments: 2 Last Update: May 05, 2008     Asked by: ujvala 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: karthik_jeeva
 
Answer is Structure is Value type

Above answer was rated as good by the following members:
RoMBiN
January 24, 2008 05:46:24   #1  
baseersd Member Since: June 2007   Contribution: 34    

RE: C Structures
Hi Ujvala

I am little bit confused with the question
Are you asking like
1)Calling the function with structure as a parameter whether changes value of structure or not
2)Passing of structure can be done by value or reference?

Hope the following program helps in understanding.

#include<stdio.h>

typedef struct _address
{
int ID;
char name[20];
}address;

void copy_ByValue(address obj)
{
obj.ID 200;
strcpy(obj.name "copy_ByValue");
printf("nnDetails of obj1 in Copy_ByValue::");
printf("nID :: d" obj.ID);
printf("nName :: s" obj.name);
}
void copy_ByReference(address* obj)
{
obj->ID 300;
strcpy(obj->name "copy_ByReference");
printf("nnDetails of obj1 in copy_ByReference::");
printf("nID :: d" obj->ID);
printf("nName :: s" obj->name);
}
int main()
{
address obj1;

obj1.ID 100;
strcpy(obj1.name "C Structures");

printf("nnDetails of obj1 ::");
printf("nID :: d" obj1.ID);
printf("nName :: s" obj1.name);

copy_ByValue(obj1);
printf("nnDetails of obj1 after Copy_ByValue::");
printf("nID :: d" obj1.ID);
printf("nName :: s" obj1.name);
copy_ByReference(&obj1);
printf("nnDetails of obj1::");
printf("nID :: d" obj1.ID);
printf("nName :: s" obj1.name);

getch();
}

 
Is this answer useful? Yes | No
May 05, 2008 10:20:31   #2  
karthik_jeeva Member Since: May 2008   Contribution: 1    

RE: C Structures
Answer is Structure is Value type
 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    

 Related Questions

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 ...

Some operating systems (such as UNIX or Windows in enhanced mode) use virtual memory. Virtual memory is a technique for making a machine behave as if it had more memory than it really has, by using disk 
Latest Answer : First of all there is a one sentence definition of Page Thrashing (I believe someone posted a similar answer here):Page Thrashing only comes about when you use Virtual Memory which requires an MMU and "fools" a process into believing that it ...

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. ...

The heap is where malloc(), calloc(), and realloc() get memory. Getting memory from the heap is much slower than getting it from the stack. On the other hand, the heap is much more flexible than the stack. 
Latest Answer : Heap is a dynamic memory of main memory. In main memory there are several type of memory management like fixed, static, dynamic (it is just memory area which can be used by any task or process but it is not contiguous memory location). Now the point ...

Q1 Given an array of characters. How would you reverse it. ? How would you reverse it without using indexing in the array ?Q2 How can I call a function, given its name as a string? Q3 How can I invoke another program from within a C program? Q4 How can I access memory located at a certain address? Q5 How can I allocate arrays or structures bigger than 64K? Q6 How can I find out how much memory is available? Q7 How can I read a directory in a C program? Q8 How can I increase the allowable
View Question | Asked by : rameshwar83

Is structure a value type or a reference type? why? 
Latest Answer : Answer is Structure is Value type ...
Read Answers (2) | Asked by : ujvala


 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
 

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
 

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
 

Programming Languages Certification

IT Certification programs have several options that will offer you the best knowledge.&nbsp; By learning everything that you need to know about information technology you will be able to open new doors to your career and personal business desires.&nbsp; IT Certification offers several vari
 

JavaScript Iterative Structures - Part II

JavaScript Iterative Structures Part II In this JavaScript tutorial you will learn about JavaScript Iterative Structures while loop and do while loop explained along with syntax and examples mosgoogle center while loop This looping structure is used when a programmer wants the block of code to exec
 

JavaScript Iterative Structures - Part I

JavaScript Iterative Structures Part I In this JavaScript tutorial you will learn about JavaScript Iterative Structures for loop for in statement break and continue explained along with syntax and examples mosgoogle center Iterative Structures are used to execute a certain piece of code a specified
 

Neuro-linguistic Programming Methods

Neuro linguistic Programming Methods There are several methods used for performing Neuro linguistic Programming on an individual for obtaining insights into the psyche of the person in order to correct to modify certain patterns of behavior These techniques are also used for Neuro linguistic trainin
 

Importance of Proper English during Job Interview

Importance of Proper English during Job Interview Your job interview is crucially important and it will determine whether or not you will get the job Depending on the type of job you re going for it is very important for you to use proper English In most cases jobs which offer higher salaries will h
 

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