Void vs Int Functions
And is int used when you actually do calculations within it?
8 Answers 8
void is used when you are not required to return anything from the function to the caller of the function.
int is used when you have to return an integer value from the function to the caller of the function
![]()
Do you want the function to return anything? If not, then it should be void . If you want it to return an int , then it should be int . If you want it to return something else, then it should have some other return type.
Some prefer using functions that return int to indicate some errors or special cases. Consider this code:
![]()
when you use void, it means you don’t want anything returned from the function. while an int return may be a result of calculation in the function, or indicate the status when it returning, such as an error number or something else that can tell you what has happened when the function executing.
Like you heard above, void doesn’t return value, so you use it when you don’t need to do this. For example, you can use ‘void’ not only to print text, but mainly to modificate a parameters (change something you already have), so you don’t need to return a value.
Let’s say you want to find int c , which is sum two (integer) numbers, a and b (so a+b=c). You can write a function which adds these numbers and assign it’s value to c
While using void , you will just modificate c , so instead of writing c = function(arguments) , you will have function(c) which modifies c , for example:
After the last line, the ‘ c ‘ you have is equal the sum of ‘ a ‘ and ‘ b ‘ 🙂
Чем void отличается от int c
[Note: This was true for older versions of C but has been changed in C11 (and newer versions). In newer versions, foo() is same as foo(void). Refer this -> https://port70.net/
Consider the following two definitions of main().
What is the difference?
In C++, there is no difference, both are same.
Both definitions work in C also, but the second definition with void is considered technically better as it clearly specifies that main can only be called without any parameter.
In C, if a function signature doesn’t specify any argument, it means that the function can be called with any number of parameters or without any parameters. For example, try to compile and run following two C programs (remember to save your files as .c). Note the difference between two signatures of fun().
Output of C code:
Output of C++ code:
The above program compiles and runs fine (See this), but the following program fails in compilation (see this)
Output of C/C++ Code:
Unlike C, in C++, both of the above programs fails in compilation. In C++, both fun() and fun(void) are same.
So the difference is, in C, int main() can be called with any number of arguments, but int main(void) can only be called without any argument. Although it doesn’t make any difference most of the times, using “int main(void)” is a recommended practice in C.
Exercise:
Predict the output of following C programs.
Question 1
Question 2
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above
Data Types in C — Integer, Floating Point, and Void Explained

There are several different ways to store data in C, and they are all unique from each other. The types of data that information can be stored as are called data types. C is much less forgiving about data types than other languages. As a result, it’s important to make sure that you understand the existing data types, their abilities, and their limitations.
One quirk of C’s data types is that they depend entirely on the hardware that you’re running your code on. An int on your laptop will be smaller than an int on a supercomputer, so knowing the limitations of the hardware you’re working on is important. This is also why the data types are defined as being minimums- an int value, as you will learn, is at minimum -32767 to 32767: on certain machines, it will be able to store even more values that this.
There are two categories that we can break this into: integers, and floating point numbers. Integers are whole numbers. They can be positive, negative, or zero. Numbers like -321, 497, 19345, and -976812 are all perfectly valid integers, but 4.5 is not because 4.5 is not a whole number.
Floating point numbers are numbers with a decimal. Like integers, -321, 497, 19345, and -976812 are all valid, but now 4.5, 0.0004, -324.984, and other non-whole numbers are valid too.
C allows us to choose between several different options with our data types because they are all stored in different ways on the computer. As a result, it is important to be aware of the abilities and limitations of each data type to choose the most appropriate one.
Integer data types
Characters: char
char holds characters- things like letters, punctuation, and spaces. In a computer, characters are stored as numbers, so char holds integer values that represent characters. The actual translation is described by the ASCII standard. Here’s a handy table for looking up that.
The actual size, like all other data types in C, depends on the hardware you’re working on. By minimum, it is at least 8 bits, so you will have at least 0 to 127. Alternatively, you can use signed char to get at least -128 to 127.
Standard Integers: int
The amount of memory that a single int takes depends on the hardware. However, you can expect an int to be at least 16 bits in size. This means that it can store values from -32,768 to 32,767, or more depending on hardware.
Like all of these other data types, there is an unsigned variant that can be used. The unsigned int can be positive and zero but not negative, so it can store values from 0 to 65,535, or more depending on hardware.
Short integers: short
This doesn’t get used often, but it’s good to know that it exists. Like int, it can store -32768 to 32767. Unlike int, however, this is the extent of its ability. Anywhere you can use short , you can use int .
Longer integers: long
The long data type stores integers like int , but gives a wider range of values at the cost of taking more memory. Long stores at least 32 bits, giving it a range of -2,147,483,648 to 2,147,483,647. Alternatively, use unsigned long for a range of 0 to 4,294,967,295.
Even longer integers: long long
The long long data type is overkill for just about every application, but C will let you use it anyway. It’s capable of storing at least −9,223,372,036,854,775,807 to 9,223,372,036,854,775,807. Alternatively, get even more overkill with unsigned long long , which will give you at least 0 to 18,446,744,073,709,551,615.
Floating point number data types
Basic Floating point numbers: float
float takes at least 32 bits to store, but gives us 6 decimal places from 1.2E-38 to 3.4E+38.
Doubles: double
double takes double the memory of float (so at least 64 bits). In return, double can provide 15 decimal place from 2.3E-308 to 1.7E+308.
Getting a wider range of doubles: long double
long double takes at least 80 bits. As a result, we can get 19 decimal places from 3.4E-4932 to 1.1E+4932.
Picking the right data type
C makes pick the data type, and makes us be very specific and intentional about the way that we do this. This gives you a lot of power over your code, but it’s important to pick the right one.
In general, you should pick the minimum for your task. If you know you’ll be counting from integer 1 to 10, you don’t need a long and you don’t need a double. If you know that you will never have negative values, look into using the unsigned variants of the data types. By providing this functionality rather than doing it automatically, C is able to produce very light and efficient code. However, it’s up to you as the programmer to understand the abilities and limitations, and choose accordingly.
We can use the sizeof() operator to check the size of a variable. See the following C program for the usage of the various data types:
Output:
The Void type
The void type specifies that no value is available. It is used in three kinds of situations:
1. Function returns as void
There are various functions in C which do not return any value or you can say they return void. A function with no return value has the return type as void. For example, void exit (int status);
2. Function arguments as void
There are various functions in C which do not accept any parameter. A function with no parameter can accept a void. For example, int rand(void);
3. Pointers to void
A pointer of type void * represents the address of an object, but not its type. For example, a memory allocation function void *malloc( size_t size); returns a pointer to void which can be casted to any data type.
Возврат функции, int/void в чём различие. C++?

Скриншот — это дело уважения. Посмотри на ситуацию вот как.
Ты проявляешь уважение к своим собеседникам и не перегружаешь свой вопрос ненужной информацией. Скриншоты среды разработки — это очень сильная перегрузка информацией, с заведомо испорченным отображением текста — т.е. информации важной.
Еще твой вопрос могут читать люди с не очень хорошей линией интернета, через мобильное устройство или слабую публичную сеть, возможно в период плановых работ провайдера и перебоев с трафиком.
В ответ на уважение комментаторы тоже постараются проявить уважение к тебе даже если твой вопрос тянет на полное незнание основ используемого инструмента.
Есть еще один момент. Если ответ тебе действительно помог, отметь его как решение. Это никак не остановит будущие ответы и предложение иного столь же полезного решения для твоей ситуации.

За код скриншотом надо убивать ржавой секирой ужоса.
У вас там Int бесполезен по сути.
Мало того что вы никуда не присваиваете значение, которое возвращает функция, так еще и возвращаете постоянно ноль.
Конкретно в вашем случае — да, надо через указатели, потому что вы хотите модифицировать в функции переменные, переданные извне, да еще и больше одной.