Skip to main content
0 online

C++ anyone?

ok4now by ok4now · May 28, 2003 · 335 views · Ask eZabel

i'm looking for help with some programming in c++. anyone know how to use pointers with functions?


here's what i have:


#include <iostream>

#include <iomanip>
using namespace std;
const int NumCells = 7;
void main(void)
{
exec(NumCells);
cout << "End of program." << endl;
}

void exec(int size)
{
int *p;
p=new int [size];
Purpose(size);
PopulateArray(*p, size);
:
:
void PopulateArray(int r, int size)
{
int *q=&r;
for (int i=0; i<size; ++i)
{
cout << "Please enter value " << i+1 << ": ";
cin >> *(q+i);
}
return;
}:
:


the problem right now is that the program asks for 14 values instead of 7, and then crashes....any ideas?

To contribute to the discussion, please log in.

44 Comments

ok4now #1 ok4nowOG 2002

alright, then...i'll check back tomorrow

skaorsk8 #1.1 skaorsk8OG 2002

i refuse to look at this. this reminds me of college. so, no.

flyingfree1125 #2 flyingfree1125OG 2001

i dont know... this confuses me deeply

katiedid #3 katiedidFounder

I almost had a seizure looking at that. You can borrow my c++ book if you think that'll help, but honestly, functions is where it all started going downhill.

forrestina #3.1 forrestinaOG 2002

haha recursive functions

rocksupastar #4 rocksupastarFounder

hahaha, ask funky fresh, hes the MAN at C++, I would check it out, but i probably would just screw it up...

ok4now #4.1 ok4nowOG 2002

(moved)    

thefunkyfresh #4.2 thefunkyfreshFounder

haha, wow, thanks mike, but i think i'm retired for now. i can't look at this stuff without getting headaches.

magnum #5 magnumOG 2001

all u want to do is ask for 7 values and put them into a array? if so what the heck are you doing, that program is huge just to do something so little

ok4now #5.1 ok4nowOG 2002

well, joe, if u noticed the little ": : :" marks, u'd realize there's more to the program. there's about 8 other functions in there. even though the whole program could be about 30 lines, we're learning about using functions and passing parameters.

deanh77 #6 deanh77Founder

man, so glad I took up java. C++ hurts my head. maybe I'll pick it up again just for fun.

deanh77 #7 deanh77Founder

what does Purpose(int x) do? if it takes the argument by reference, and then doubles it, that'd be a reason the loop goes 14 times instead of 7.

ok4now #7.1 ok4nowOG 2002

Purpose() is just a template function to explain the purpose of the program. it says something like, "this program takes SIZE elements into an array" blah-blah-blah. i made it so it would change if the global variable changed.

deanh77 #8 deanh77Founder

for (int i=0; i> *(q+i);
}

that can't be good syntax, did you copy and paste this program wrong?

ok4now #8.1 ok4nowOG 2002

good pickup. it seems the <pre> tags work great with double <<'s, but not with single ones. take another look.

magnum #9 magnumOG 2001

where is declaration of some of these integers you are using?

deanh77 #9.1 deanh77Founder

he has "const int Numcells = 7;" on the top.

O
#10 orbitzOG 2001

First of all:

void main is incorrect.

It should be int main(). And because it's int main() it should have a return statment. Although in C++ that is not required.


Secondly, you should read the section of your book on pointers. Your problem is at:


void PopulateArray(int r, int size)


Just because you are using pointers does not mean the laws of the language have changed. In this, r is a local variable containing one value which is an integer.


This means that:
*(q+i)


Is out of bounds, since int r only holds one location for an integer.


Also, your conditional makes very little sense.


for (int i=0; i> *(q+i);
(I assume you mean to finish that as i++)


You want to interate while i is greater than the value at q[i]? What? This means your code is quickly going to go out of bounds of q..


You should seriously reread the section of yoru book on pointers. If your book is no good, Thinking In C++ by Bruce Eckel is available freely online, just google for it.

ok4now #10.1 ok4nowOG 2002

please take another look...the paste didn't work right because i left a < sign which turned everything else into an html tag. question: how do i pass a pointer to a function? or, how do i pass a dynamically created array to a function (without using indices)?

C
#11 chuckthecloneOG 2002

and c++ is?????

forrestina #11.1 forrestinaOG 2002

c ++ for you ++ (at least that was our textbook title)

O
#12 orbitzOG 2001

Your book will explain this concept very easily. And like I said, Thinking In C++ is free online. You aren't declaring your parameters to your function as a pointer. Try reading what I said again, and actually read it. Nobody likes to answer peoples questions if they can't even do the research themselves.

ok4now #12.1 ok4nowOG 2002

  1. i did read what you wrote. since much of your answer was based on a bad paste, i didn't comment further.

  2. you wrote: "Just because you are using pointers does not mean the laws of the language have changed. In this, r is a local variable containing one value which is an integer." well, i don't want 'r' to be a local integer. i want it to accept the address of 'p' in the scope of exec() and store it in another pointer. thus, i'm not finding any reference in my books or the internet for this answer. hence my reason for posting it here.

  3. no need to get snitty. if ur finished offering suggestions, then thanks. i'll look for 'thinking in c++' and see what else i can find.

  4. my professor tells me to use this:

    It should read:

    PopulateArray(p, size);
    :
    :
    void PopulateArray(int * p, int size)
    {
    :
    }


    however, when i compile this, i get: 'PopulateArray': cannot convert parameter 1 from 'int *' to 'int'

    so, as you can see, the professor hasn't been much help on this. another reason for this journal.

ok4now #12.2 ok4nowOG 2002

although it's an old book, it looks like a good reference. unfortunately, he's referencing a style of c++ that i am not learning. regarding pointers and functions, he references "int*" and "int&" which i haven't been taught. the handling is much different than the functions my professor is looking for. thanks anyway.



btw, if anyone else wants the book, you can get it here: planet pdf

ok4now #12.2.1 ok4nowOG 2002

although this is a different method, it made me look at the error message in a different way. it appears the function prototype was wrong. it needed to be: PopulateArray(int *, int), not (int, int). Because we have been learning about "*p" and "*r" and not "int*", i wasn't seeing the need to change to prototype. now with my newfound powers...

O
#13 orbitzOG 2001

It's like this, take a fucntion:

void blah(int r)



r is a local variable. It's value is initialized to whatever you pass it. Just because it's in a parameter list does not mean it isn't a local variable. All changes to it are forgotten once the function exits. int r is not a pointer, it is an int. We know this because of its type: int.

If it were a pointer its type would be int*.



When we make assignments, we need to make sure our types match. This is especially true in C++, because it is a strongly typed language. The compiler will not allow you to assign an int to an int*, and vice versa.



So looking at your original code:

void PopulateArray(int r, int size)

{

int *q=&r;



What does this accomplish? int r is a local variable. Imagine this:

int r;

int *q = &r;



What does q point to? Just r, *q is the same as r.



*q = 3;

cout << r; will give us 3.



So looking at your code, q is rather frivilous, since we can access r the same.



Now let's look at how you called this function:



int *p;

p=new int [size];

PopulateArray(*p, size);



p points to an block of memory holding 'size'-many integers. This block is located whereever p is pointer to. what is *p? *p would be equivalaent to p[0]. Remember, p[n] == *(p + n), so p[0] == *p. What type is p? It is an int*. What type is *p? It is an int. *p is an integer value. It contains no information about where it is located, that is the point of p. So when you call PopulateArray, you are passing an int, not a block of memory containing 'size'-many integers.



How do we declare a pointer? You just did it:

int *p



Declarations in function parameters are the same as anywhere else.

You just have to make sure your types line up. If PopulateArray wants an int*, then you better give it an int*.



You can ignore int& for now. It is a reference, and will make sense after pointers make sense.

ok4now #13.1 ok4nowOG 2002

thanks for your help. i already knew about 98% of what you wrote. the new point is that in "int *p;" that i was taught, c++ sees it as "int* p;". now that i know the asterisk goes with the datatype, i was able to fix my program.

ok4now #13.1.1 ok4nowOG 2002

here's the final animal:



//Brian W. Papocchia

//Programming Assignment Set 3
//Part 3, Array version 9 - Use functions with pointers
// Output: array forwards, total, array in reverse, highest & lowest elements,
// ascending, even numbers, prime numbers
//May 29, 2003

#include <iostream>
#include <iomanip>
#include <math.h>
using namespace std;

const int NumCells = 7; // change to allow more numbers in array

// function prototypes
void exec(int); //Call other functions
void Purpose(int); //Explain purpose of program
void PopulateArray(int *, int); //Allow user to input array
void PrintArray(int *, int); //Display array on screen
void Separator(void); //Display a line separator
void SumArray(int *, int); //Sum all elements in array
void ReverseArray1(int *, int); //Reverse array using a temporary array
void ReverseArray2(int *, int); //Reverse array using a temporary variable
int SeekHighest(int *, int); //Find highest value in array
int SeekLowest(int *, int); //Find lowest value in array
void Sort(int *, int); //Sort array
void Swap(int *, int, int); //Swap to array elements
void PrintEvens(int *, int); //Print even values from array
void PrintPrime(int *, int); //Print all prime values in array

void main(void)
{
exec(NumCells);
cout << "End of program." << endl;
}

void exec(int size)
{
int *p; //create pointer variable
p=new int [size];

Purpose(size);
PopulateArray(p, size);
Separator();

//Output array forwards
cout << "Here are the values you entered." << endl;
cout << endl;

PrintArray(p, size);
Separator();
SumArray(p, size);
Separator();

//Output array in reverse with temporary array function
ReverseArray1(p, size);
cout << "Here are the values you entered in reverse." << endl;
cout << endl;
PrintArray(p, size);
Separator();

//Output array in original order with one-variable function
ReverseArray2(p, size);
cout << "Here are the values in their original order." << endl;
cout << endl;
PrintArray(p, size);
Separator();

cout << "The highest value entered was: ";
cout << setw(6) << SeekHighest(p, size) << "." << endl;
Separator();
cout << "The lowest value entered was: ";
cout << setw(6) << SeekLowest(p, size) << "." << endl;
Separator();

Sort(p, size);
cout << "Here are the values sorted in ascending order." << endl;
cout << endl;
PrintArray(p, size);
Separator();

PrintEvens(p, size);
Separator();
PrintPrime(p, size);
cout << endl;

delete []p; //release memory back to system
p=0; //clear address
}

void Purpose(int size) //Explain purpose of program
{
cout << "This program accepts " << size << " elements into an array." << endl;
cout << "It then displays the values entered, and sums the values." << endl;
cout << "Next, it displays the values in reverse order." << endl;
cout << "Then, it will display the highest and the lowest values entered." << endl;
cout << "Finally, it will display any even or prime values entered." << endl;
cout << "Please enter whole numbers only. Thank you." << endl;
cout << endl;
return;
}

void PopulateArray(int *q, int size)
{
for (int i=0; i<size; ++i)
{
cout << "Please enter value " << i+1 << ": ";
cin >> *(q+i);
}
return;
}

void PrintArray(int *q, int size)
{
for (int i=0; i<size; ++i)
cout << "Array element " << i+1 << ": " << *(q+i) << endl;
return;
}

void Separator(void)
{
cout << endl;
cout << "---------------------------------------------------------------" << endl;
return;
}

void SumArray(int *q, int size)
{
int sum=0;
//Total array and print result
for (int i=0; i<size; ++i)
sum+=*(q+i);
cout << "All values in the array add up to: " << sum << "." << endl;
return;
}

void ReverseArray1(int *q, int size)
{
int i, k; // loop variables
int *r;
r = new int[size];
k = size-1;
for (i=0; i<size; i++) // reverse OrigArray into TempArray
{
(*(r+k))=(*(q+i));
k--;
}
for (i=0; i<size; i++)
(*(q+i))=(*(r+i));

delete []r; //release memory back to system
r=NULL; //initialize 'r' to no address
return; // end function
}

void ReverseArray2(int *q, int size)
{
int i, k; // loop variables
int Temp; // placeholder while reversing array

k = size-1; // count down from end of array
for (i=0; i<(size/2); ++i)
{
Temp=(*(q+i));
(*(q+i))=(*(q+k));
(*(q+k))=Temp;
k--;
}
return; // end function
}

int SeekHighest(int *q, int size) //Find highest value in array
{
int max;
max = *(q+0); //initialize to first element

for (int i=1; i<size; ++i) //Start with [1] because [0] assigned above
if ((*(q+i)) > max)
max = (*(q+i));
return max;
}

int SeekLowest(int *q, int size) //Find lowest value in array
{
int min;
min = *(q+0); //initialize to first element

for (int i=1; i<size; ++i) //Start with [1] because [0] assigned above
if ((*(q+i)) < min)
min = (*(q+i)); //find lowest value
return min;
}

void Sort(int *q, int size) //Sort array with Bubble sort
{
for (int i=1; i<size; i++) //keep track of passes thru array
for (int k=0; k<size-i; k++)
if ((*(q+k)) > (*(q+(k+1))))
Swap(q, k, k+1); //swap places
}

void Swap(int *r, int first, int second)
{
int temp;
temp=(*(r+first));
(*(r+first))=(*(r+second));
(*(r+second))=temp;
}

void PrintEvens(int *r, int size) //Print even values from array
{
bool even=0; //set flag to false, i.e. no even values
for (int i=0; i<size; i++)
{
if ((*(r+i))%2==0) //number is even
{
if (!even)
even=1; //set flag to true once
cout << "Array element " << i+1 << ": " << (*(r+i)) << " is even." << endl;
}
}
if (!even)
cout << "There are no even values in the array." << endl;
return; //end function
}

void PrintPrime(int *r, int size) //Print all prime values in array
{
bool prime;
int numprimes=0; //count number of primes
int end;
int i,k; //loop variables
for (i=0; i<size; i++)
{
if ((*(r+i))>1) //prime numbers are greater than one
{
end=(int)sqrt((*(r+i)));
prime=1; //set flag to true
for (k=2; k<=end; k++)
{
if (((*(r+i)) % k)==0) //if true, value not prime
{
prime=0;
break;
}
} //end for loop with k
if (prime)
{
cout << "Array element " << i+1 << ": "
<< (*(r+i)) << " is prime." << endl;
numprimes++;
} //end if
prime=1; //reset flag to true
} //end if
} //end for loop with i
if (numprimes==0)
{
cout << "There are no prime values in the array." << endl;
}
return; //end function
}

ok4now #13.1.1.1 ok4nowOG 2002

i'm going to bed now

ok4now #13.1.1.2 ok4nowOG 2002

i can't find the code leak in this...can you?

katiedid #14 katiedidFounder

random

#include <>

#include <>
#include "boolean.h">

const char skip = ' ';
const int max_list_size= 5;
const float inputSentinel = -999.0;

void print_greeting();
void get_data(float list[ ], int &length);
void print_list(float list[ ], int length);
void sort_list(float list[ ], int length);
int find_minimum(float list[ ], int first, int length);

void swap(float &x, float &y);
boolean end_of_input(float data);

int main()
{
int length = max_list_size;
float list[max_list_size];

print_greeting();
get_data(list, length);
cout << setw(10) << skip << "Listed numbers: " << endl;
cout << endl;
print_list(list, length);
sort_list(list, length);
cout << setw(10) << skip << "Sorted list: " << endl;
cout << endl;
print_list(list, length);
return 0;
}

void get_data(float list[ ], int &length)
{
int logical_length = 0;
float data;

cout << "Enter a real number (-999 to stop input): ";
cin >> data;

while((logical_length < length) && ! end_of_input(data))
{
list[logical_length] = data;
++logical_length;
cout << "Enter a real number (-999 to stop input): ";
cin >> data;
}
if (! end_of_input(data) && (logical_length == length))
cout << "There is more data." << endl;
length = logical_length;
}

void print_list(float list[ ], int length)
{
cout << endl;
for (int j = 0; j < length; ++j)
cout << setw(12) << skip << '<' << j + 1 << '>' << setw(6)
<< list[j]
<< endl;
}

void sort_list(float list[ ], int length)
{
int min_index = 0;
for (int j=0; j < length - 1; ++j)
{
min_index = find_minimum(list, j, length);
if (min_index !=j)
swap(list[j], list[min_index]);
}
}

int find_minimum(float list[ ], int first, int length)
{
int min_index = first;
for (int j = first + 1; j < length; ++j)
if (list[j] < list[min_index])
min_index = j;
return min_index;
}

void swap(float &x, float &y)
{
float temp = x;
x = y;
y = temp;
}

boolean end_of_input(float data)
{
return data == input_sentinel;
}

katiedid #14.1 katiedidFounder

after the #include should be "iostream.h" and "inmanip.h" for whatever reason. this may work (doubtful) in case you need something later on. lol.

ok4now #14.2 ok4nowOG 2002

i swear u must have the same prof! lol...this looks very close to my assignment.

ok4now #15 ok4nowOG 2002

while we're on the subject...any idea why this won't work for all ranges?



//Brian W. Papocchia

//Programming Assignment Set 3
//Part 4, Guessing Game program
//May 29, 2003

#include <iostream>
#include <iomanip>
#include <stdlib.h>
#include <time.h>
using namespace std;

void Instructions(void); //game instructions
void GetRange(int &, int &); //ask user for range to guess within
void GetSeed(void); //set the random number generator seed
int GetRandom(int &, int &); //set a random integer in range
void PlayGame(int &, int &); //game routine
void YouWin(int &, int &, int); //user guesses number
void YouLose(int &); //user fails to guess number

void main(void)
{
int from, to; //range to guess within

Instructions();
GetRange(from, to);
while (from>0 || to>0)
{
PlayGame(from, to);
cout << "If you want to play again..." << endl;
GetRange(from, to);
cout << endl;
}
cout << "Game over." << endl;
}

void Instructions(void) //game instructions
{
cout << "This program is a Guessing Game." << endl;
cout << "You will have 10 guesses at my number." << endl;
cout << "I will tell you if your guess is too high or too low." << endl;
cout << "You can even define the range for my number (ex. 1 to 100)." << endl;
cout << "---------------------------------------------------------------" << endl;
}

void GetRange(int &from, int &to) //set range of number to guess within
{
cout << "Please enter a range from which to guess." << endl;
cout << "Enter two zeros or negative numbers to stop the program." << endl;
cout << "---------------------------------------------------------------" << endl;
cout << "Enter the low end of the range: ";
cin >> from;
cout << "Enter the high end of the range: ";
cin >> to;
cout << "---------------------------------------------------------------" << endl;
return;
}

void GetSeed(void) //set the random number generator seed
{
srand(unsigned(time((time_t *)NULL))); /*sets seed based on computer time
thus seed will be different on each execution of program*/
}

int GetRandom(int &low, int &high) //set a random integer in range
{
double random;
random = rand() / ((double)(RAND_MAX) + 1);
return (int)((high * random) + low);
}

void PlayGame(int &from, int &to)
{
const int maxguesses = 10; //set maximum allowed guesses
int count; //count guesses
int guess; //store user's guess
int number; //computer's number to guess

GetSeed();
number = GetRandom(from, to);
count = 1;
while (count <= maxguesses)
{
cout << "What is your guess? ";
cin >> guess;
if (guess == number)
{
YouWin(number, count, maxguesses);
break; //break out of while loop
}
else if (guess > number)
cout << "Your guess is too high." << endl;
else cout << "Your guess is too low." << endl;
cout << endl;
count++;
}
if (count > maxguesses)
YouLose(number);
return;
}

void YouWin(int &num, int &guesses, int allowed)
{
cout << "---------------------------------------------------------------" << endl;
cout << "VERY GOOD!!!" << endl;
cout << endl;
cout << "My number was "<< setw(4) << num << ", and you got it in " << guesses;
if (guesses == 1)
cout << " try! Did you cheat? *wink*";
else cout << " tries.";
cout << endl;
if (guesses == allowed)
cout << "WHEW!!! YOU JUST MADE IT!!!" << endl;
cout << "---------------------------------------------------------------" << endl;
cout << endl;
return;
}

void YouLose(int &num)
{
cout << "I'm sorry. You are out of guesses." << endl;
cout << "My number was: " << num << "." << endl;
cout << "---------------------------------------------------------------" << endl;
cout << endl;
return;
}

ok4now #15.1 ok4nowOG 2002

works good for 1 to 100, or even 1 to 3. But, pick 44 to 46, and the number ends up as 68. weird...i'll have to look at it some more tomorrow.

katiedid #15.2 katiedidFounder

I made a game similiar to that in VB. I also did a tic tac toe game in C++ (if I can find it). stupid languages.....

deanh77 #16 deanh77Founder

ok, I think you might have piqued my interest in C++ up again...

thefunkyfresh #16.1 thefunkyfreshFounder

haha, it's spelt "picked", lol, silly

forrestina #16.2 forrestinaOG 2002

i always thought it was just "peaked"...thanks for the vocabulary expansion

ok4now #16.2.1 ok4nowOG 2002

it's a great scrabble(r) word

forrestina #16.2.1.1 forrestinaOG 2002

not too often you can use "q"

O
#17 orbitzOG 2001

Just a note:

the * does not really go with the datatype, but it does define its type. For instance:

int *p, q; is the same as

int *p;

int q;



to make 2 pointers it would be:

int *p, *q;



As for your other code:

Random nitpicks:

#include cstdlib and ctime



.h files are C, not C++ and thusly none standard



int main()!!!!!!!

void main() is just plain wrong.



void functions don't need a return, the compiler does this automatically for us.



This is a REAL REAL nitpick, but stylistically, functions should be named after what they do. GetSeed makes us think it returns a value (due to get). You should really name things more along the lines of what they do. Something like 'randomize' or 'seedrand' might be more informative. But stuff like that will come after you have the language down a bit more.





To get more to the point of your problem, it is right here:

int GetRandom(int &low, int &high) //set a random integer in range

{

double random;

random = rand() / ((double)(RAND_MAX) + 1);

return (int)((high * random) + low);

}



I'm not sure exactly what this is supposed to do...



rand() returns a number between 0 and RAND_MAX, inclusive. Follow our elementry math skills, random will be somewhere between 0 and RAND_MAX/(RAND_MAX + 1) (which is slightly below 0). So then you take this number, multiply it by 'high', and then add 'low' to it. Think of this in terms of percents.



So we get some number between 0 and high, excluding high, and then add low to it. So we get values between low and high + low (more or less). Now, I introduce you to Mr. Subtraction. Try turning this into a nice little equaltion:



random multiplied by the difference between high and low, then add low.

ok4now #17.1 ok4nowOG 2002

thanks for the suggestions. here are some responses:

i know that int *p, q; is the same as int *p; int q;

i guess i'm not seeing it all just yet, because i don't fully understand why the prototype is "function(int *);" i'm doing it now cuz it works.


i'm trying to get away from the .h files. but my compiler didn't have them without the .h. do u think i can manually rename the files? do i have to install additional libraries? for time's sake, i just added the .h so the compiler stopped complaining. (btw, i'm using Visual Studio 6.0)


i know u said 'int main()' before. right now, the professor wants it this way. we're not returning a code to the OS, so it really doesn't matter right now. (does it?)


i know void functions don't need return. i don't think i was consistent, but i wanted the empty returns to be clear that no value was returned. i was told it's optional.


it's a funny thing u said about the function names. just today, i learned about the 'get' method for i/o. now i see a confusion with 'getseed'. before today, i just read it as 'go get a seed value' and 'go get a random number'. they'll get changed now.


i actually referenced the wrong page in my book for the random function. the return code i ended up using was:

return (int)((high - low) * random + low);

u said 'you're not sure exactly what this is supposed to do...', but then you explain it anyway. so i'm figuring you get it.

  • RAND_MAX, of course, is the highest random integer (usually 32,728 or something).

  • (double)(RAND_MAX) type casts the integer to a double

  • rand()/((double)(RAND_MAX)+1); gives a small number (like 0.6523829)

  • return (int)((high - low) * random + low); should type cast the double into an integer. and this is supposed to be inclusive, but i couldn't prove it. choosing a range of 1 and 3, the answer was always 2 (after 10 tries...i'm not gonna keep running the program at 3am!)


anyway...everything's turned in, and i'm onto the next assignment. now we're doing file i/o with a high score file, creating an encrypted file and decrypting a file....oh goodie!

O
#18 orbitzOG 2001

i guess i'm not seeing it all just yet, because i don't fully understand why the prototype is "function(int *);" i'm doing it now cuz it works.



Well think about it, a function prototype defines the return type, name, and types of the values that function takes.

All those parameters are, are names for variables your function can use, who's value is initiialized on funciton call.



That's hard to bite, but read it a few times.





About header files: Try using a conforming compiler. MS has allready declared that they will not make one. Dev-C++ is good



i know u said 'int main()' before. right now, the professor wants it this way. we're not returning a code to the OS, so it really doesn't matter right now. (does it?)

Sure does, your shell wants that return value, and expects it. The C/C++ standard defines the 2 ways inwhich main will be defined, and both of those ways have a return value of int. In C++, they say you leavea bout the return statement though.



Example:

int main(void)

{

}



is valid. Even though there should be a return statement (with a value).



i know void functions don't need return. i don't think i was consistent, but i wanted the empty returns to be clear that no value was returned. i was told it's optional.

They probably mean the return type was optional. Everything defaults to an int in C/C++ (although not in the last standard, but anyways). So everything has a default type of int if not given.



Example:

main(void)

{

}

is the same as

int main(void)

{

}



u said 'you're not sure exactly what this is supposed to do...', but then you explain it anyway. so i'm figuring you get it.



i was just being a jerk.

Welcome Back to eZabel

It's been a while. Here's what's new.

eZabel Lore

A complete history of our community — stats, Hall of Fame, legendary threads, and more.

View the Lore →

Curator Commentary

Look for the blue speech bubbles on threads, profiles, and news — notes and context from iwz.

Everything Preserved

All 225,969 pieces of content from 2000–2014 are here — forums, messages, journals, photos, polls, and events.