Questions about Function,Variable & Exception Handling

Hello,

I'm new to C++ & new to this forum.

I've these questions for now :)

## Function:
1
2
void function1(int x, int y);
int function1(int x, int y);


When to use void & when to int while declaring a function?

## Variable:
signed
unsigned

Is any of these set by default for variables?

## Exception Handling:
How to Exception Handling for data types?
Example, a user can only enter double type data, others will be ignored with an error message.


Any help please.

Thanks.
When you declare a function an int or string, or char etc it means you will be returning that data type. So the int function means you will be returning an integer value. Like in main, when you start up a new project in main there will be return 0; thats why main is an int because its returning the integer value of 0. the same is with strings chars etc. Void is when your function will be returning nothing at all and it has no return type.

So for example:

1
2
3
4
5
6
int addition (int x, int y)
{
  int r;
  r = x+y;
  return (r);
}


Im not sure what you want to know about signed and unsigned. and as for the last im not sure.
Last edited on
you question is not clear but if u are to use void it means there is no return type so if u try to return something it will flash error
int means their is integer type to return and that is the size of the function tooo
then e.t.c with other type
Thanks for replies.

@Ch1156
That clarifies my confusion about functions.

Im not sure what you want to know about signed and unsigned

I get that answer from a tutorial.
The difference between unsigned and signed is the accepted values. Signed ints start at 0 and span to the max positive value (unsure the specific number off the top of my head) where as unsigned starts at 0 and spans to the max positive and negative value equally (the largest positive value of an unsigned int is half of the largest positive value of a signed int). I believe I read somewhere that there is a difference when comparing an int (allows for both negative and positive values) to an unsigned int. I'm not 100% when this is the case, but don't assume that the default data type is unsigned.

In regards to data type exceptions, it's hard to compare a double against any other type of numerical data type. You can, however, compare doubles against characters and strings and determine that the value is incorrect. That is more based on the input stream than the data type itself.
Topic archived. No new replies allowed.