Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Passing by Reference
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Neb  
View profile  
 More options Apr 16 2012, 10:04 am
Newsgroups: comp.lang.c++.moderated
From: Neb <n...@nowhere.com>
Date: Mon, 16 Apr 2012 07:04:53 -0700 (PDT)
Local: Mon, Apr 16 2012 10:04 am
Subject: Passing by Reference
Hi all,

Im new to c/c++ programming and am having difficulty in passing more
than one parameter into and out of a function.

//PASS BY REFERENCE
#include <stdio.h>
void swapnum(int &i,int &j)
{
        int temp = i;
        i = j;
        j = temp;
        return;

}

int main()
{
        int a = 10;
        int b = 20;

        swapnum(a, b);
        printf("A is %d and B is %d\n", a, b);
        return (0);

}

In compiling I am recieving the error:

Error E2293 test.ccp 4: ) expected

Thanks in advance, any help is greatly appreciated.

--
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
James K. Lowden  
View profile  
 More options Apr 16 2012, 11:09 am
Newsgroups: comp.lang.c++.moderated
From: "James K. Lowden" <jklow...@speakeasy.net>
Date: Mon, 16 Apr 2012 08:09:51 -0700 (PDT)
Local: Mon, Apr 16 2012 11:09 am
Subject: Re: Passing by Reference
On Mon, 16 Apr 2012 07:04:53 -0700 (PDT)

Neb <n...@nowhere.com> wrote:
> In compiling I am recieving the error:

> Error E2293 test.ccp 4: ) expected

You're invoking the C compiler, not the C++ compiler, perhaps because
the extension you're using is ".ccp", not the conventional ".cpp".

As a beginner, I suggest you not call any program "test", only to save
yourself some confusion and frustration.  On systems other than
Windows, there is usually a program called "test", often /bin/test.
Unless you're careful, you'll invoke that test instead of yours.

Besides, you'll have a lot of tests.  Make a test directory, call it
"t", and put your program in it.  This one might be called
"t/swap.cpp".

And use <iostream>, not <stdio.h>.  It's typesafe, and it's fun.  :-)

HTH.

--jkl

--
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ulrich Eckhardt  
View profile  
 More options Apr 16 2012, 6:07 pm
Newsgroups: comp.lang.c++.moderated
From: Ulrich Eckhardt <ulrich.eckha...@dominolaser.com>
Date: Mon, 16 Apr 2012 15:07:21 -0700 (PDT)
Local: Mon, Apr 16 2012 6:07 pm
Subject: Re: Passing by Reference
Am 16.04.2012 16:04, schrieb Neb:

> Im new to c/c++ programming and am having difficulty in passing more
> than one parameter into and out of a function.

Note up front: Since this is a moderated group, you have a rather high
latency until your posting shows up. For complex questions, this doesn't
matter, but for short questions I'd either suggest the dedicated
beginners' group (comp.lang.learn.c-c++) or one of the C++ channels on
IRC, where you might get help in real time.

> #include <stdio.h>

If any book starts with teaching printf(), it is probably a bad book for
learning C++, provided you want to learn C++ and not C. Note that it
isn't clear which of those two _distinct_ languages you want to learn.

> void swapnum(int &i,int &j)
> {
>     int temp = i;
>     i = j;
>     j = temp;
>     return;
> }

Note that in <algorithm> (or was it <utility>?) is a function called
std::swap() which does exactly the above.

> Error E2293 test.ccp 4: ) expected

I haven't tried it but the code is C++ and seems actually okay. However,
I think you are compiling it with a C compiler, is that possible? The C
compiler then chokes on the references, which only C++ supports. Also
note that typically, C++ source files are called "cpp" and not "ccp".

Good luck!

Uli

--
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Neb  
View profile  
 More options Apr 17 2012, 2:52 am
Newsgroups: comp.lang.c++.moderated
From: Neb <n...@nowhere.com>
Date: Mon, 16 Apr 2012 23:52:49 -0700 (PDT)
Local: Tues, Apr 17 2012 2:52 am
Subject: Re: Passing by Reference
{ Please restrict your quoting to the minimum needed to
establish context -mod/we }

On 16/04/2012 10:04 PM, Neb wrote:

Thanks for the advice fellas.

The issue was with the filetype, should have been .cpp vs .ccp.

--
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »