Table - Returning by reference

This is a discussion on Table - Returning by reference within the C Programming forums, part of the General Programming Boards category; Hi! Code: . . . # define BIT_NUMBER 16 . . . int *nToBin (int n, int *NoOfOnes, int *TempA) ...

  1. #1
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669

    Question Table - Returning by reference

    Hi!

    Code:
    .
    .
    .
    # define BIT_NUMBER 16
    .
    .
    .
    int *nToBin (int n, int *NoOfOnes, int *TempA)
    {
    	int Temp = 0, i = 0, *BinaryNumber = NULL, Bin = 0;
    
    
    
    	if ((BinaryNumber = (int *) malloc (sizeof (int) * BIT_NUMBER)) != NULL)
    	{
    		for (i = BIT_NUMBER-1; i >= 0; i--)
    		{
    			Temp = n;
    			n    = n / 2;
    			Bin  = Temp - (n * 2);
    			if (Bin == 1)
    			{
    				(*NoOfOnes)++;
    				TempA[i-BIT_NUMBER-1] = BIT_NUMBER-i; //index
    			}
    			BinaryNumber[i] = Bin;
    		}
    	}
    	else
    	{
    		printf ("\nERROR: BinaryNumber is NULL.");
    	}
    	return BinaryNumber;
    }
    How can I return TempA which is a table of integers by a reference?
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  2. #2
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669

    Thumbs up

    OK, I solved the problem .
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. importance of returning reference in operator overloading.
    By vaibhavs17 in forum C++ Programming
    Replies: 20
    Last Post: 05-13-2009, 01:28 PM
  2. returning reference from class
    By l2u in forum C++ Programming
    Replies: 17
    Last Post: 12-16-2007, 11:21 AM
  3. Returning reference to STL String class
    By frisbee in forum C++ Programming
    Replies: 5
    Last Post: 12-29-2003, 12:39 PM
  4. MUD Concept Question
    By mrpickle in forum Game Programming
    Replies: 3
    Last Post: 12-01-2003, 12:45 PM
  5. progarm doesnt compile
    By kashifk in forum Linux Programming
    Replies: 2
    Last Post: 10-25-2003, 06:54 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21