Thread: error in calling a function

  1. #1
    Registered User
    Join Date
    Nov 2003
    Posts
    183

    Unhappy error in calling a function

    hello .
    it is a part of my program but I have an error in the 8th line . ( b=ax(a); ----> lvalue required )
    can you plz tell me what is wrong and what I must do ?

    Code:
    #include <iostream.h>
    #include <conio.h>
    
    int * ax(int *);
    
    int main(){
      int a[10],i,b[10];
      for(i=0;i<10;++i)
        cin >> a[i];
      b=ax(a);

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    You can't return an arrray - only a pointer to one

    Easiest thing to do is
    Code:
    void ax( const int *a, int *b);
    
    int main(){
      int a[10],i,b[10];
      for(i=0;i<10;++i)
        cin >> a[i];
      ax(a,b);
    ax() reads from the array a, and updates array b
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Nov 2003
    Posts
    183
    tnx .
    but if you want a function to return a pointer , how to do it ?
    there isn't any function that returns (int * ) ?

  4. #4
    Registered User
    Join Date
    Nov 2003
    Posts
    183

    Lightbulb

    I found the answer , thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  3. Calling a Thread with a Function Pointer.
    By ScrollMaster in forum Windows Programming
    Replies: 6
    Last Post: 06-10-2006, 08:56 AM
  4. Question on function syntax and calling function
    By cbrman in forum C Programming
    Replies: 10
    Last Post: 10-05-2003, 05:32 PM
  5. Calling a user-defined function in C++
    By brianptodd in forum C++ Programming
    Replies: 3
    Last Post: 10-08-2002, 12:09 PM