Webmaster Forum

Go Back   Webmaster Forum > Web Development > Coding Forum

Coding Forum Problems with your code? Discuss coding issues, including JavaScript, PHP & MySQL, HTML & CSS, Flash & ActionScript, and more.


Closed Thread
 
Thread Tools Display Modes
Share |
  #1  
Old 10-05-2016, 04:15 AM
saikumar011's Avatar
saikumar011 saikumar011 is offline
Banned
 
Join Date: 09-29-16
Location: chennai
Posts: 81
iTrader: 0 / 0%
Passing Structures to Functions

When a structure is used as an argument to a function, the entire structure is passed by using the standard call-by-value parameter passing mechanism. This, of course, means that any changes made to the contents of the structure inside the function to which it is passed do not affect the structure used as an argument. However, be aware that passing large structures can incur significant overhead. (As a general rule, the more data passed to a function, the longer it takes.)

When using a structure as a parameter, remember that the type of the argument must match the type of the parameter. For example, the following program declares a structure called sample, and then a function called f1( ) that takes a parameter of type sample.

Code:

// Pass a structure to a function.
#include <iostream>
using namespace std;
// define a structure type
struct sample {
int a;
char ch;
} ;
void f1(sample parm);
int main()
{
struct sample arg; // declare arg
arg.a = 1000;
arg.ch = 'X';
f1(arg);
return 0;
}
void f1(sample parm)
{
cout << parm.a << " " << parm.ch << "\n";
}

Here, both arg in main( ) and parm in f1( ) are of the same type. Thus, arg can be passed to f1( ). If the structure types had differed, a compile-time error would have resulted.
 

Advertisement

Advertisement

  #2  
Old 10-05-2016, 06:16 AM
snakeair snakeair is offline
Super Moderator - Rest in Peace 2018
 
Join Date: 12-31-07
Location: Medford, NJ
Posts: 54,771
iTrader: 3 / 100%
Don't steal content. This is a verbal warning to you

http://codescracker.com/cpp/cpp-pasi...-functions.htm
 
Go Back   Webmaster Forum > Web Development > Coding Forum

Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Which of these URL structures do you like the best? nat3 Web Design Lobby 4 03-23-2015 03:56 AM
Cost Structures of PPC vs SEO Marketing snakeair Marketing Forum 12 11-10-2011 01:22 PM
Directory Structures gariben Web Directory Issues 9 11-29-2004 03:24 AM
Table Structures for Top SE Positions hixe Web Design Lobby 3 10-29-2004 11:30 AM
SEO and site directory structures pitpony SEO Forum 6 04-23-2004 04:41 AM


V7N Network
Get exposure! V7N I Love Photography V7N SEO Blog V7N Directory


All times are GMT -7. The time now is 08:29 PM.
Powered by vBulletin
Copyright 2000-2014 Jelsoft Enterprises Limited.
Copyright © 2003 - 2018 VIX-WomensForum LLC