UrbanPro

Learn C++ Language from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

What is the main difference between returning value of a function and does not return any value of a function in; C. Which is correct void main(void), int main(void), int main(int) , or void main(int) and explain the main difference between int main() and int main(void).;

Asked by Last Modified  

Follow 15
Answer

Please enter your answer

Tutor

A function may or may not return a value to the calling function. If the function is returning a value, then you have to mention the data type in the function definition and funtion declaration (like int, float or double etc.). If the funtion not returning any value, then you have to mention the data...
read more

A function may or may not return a value to the calling function. If the function is returning a value, then you have to mention the data type in the function definition and funtion declaration (like int, float or double etc.). If the funtion not returning any value, then you have to mention the data type as void. If you not mention return type, then compiler take it as int data type.

 Similary, a function  may have arguments or not. If your functions have arguments, then you have to mention data types of arguments. If you are not passing any arguemtns then you may write void or simply live it blank that is depend upon the compiler. main() is a user defined function, so it follows the same rules.

read less
1 Comments

Tutor

Hi, Thanks for A2A, your 1st question is "What is the main difference between the returning value of a function and does not return any value of a function in C". the main difference between both types of the function will be its return type as the function which will not return any value will have...
read more

Hi, Thanks for A2A, your 1st question is "What is the main difference between the returning value of a function and does not return any value of a function in  C". 

the main difference between both types of the function will be its return type as the function which will not return any value will have return type "void" which means nothing wherein function with the return value should have a return type "data type" int, char, struct so ....on..while declaring/defining both !! and one more major difference will be, function with no return type (or can say void return type ) don't need any additional variable to save its return value wherein function with return value may have addition variable or additional check for return value !! 

 now coming to your 2nd question "Which is the correct void main(void), int main(void), int main(int), or void main(int) and explain the main difference between int main() and int main(void)" 

ans: best practice is to use int main(void) if it does not have command line arguments !! now using void main(void) is fine but gives warning in some compilers as the main function expected to return integer value !! now int main(int) is incorrect !!

read less
1 Comments

Training Centre

Void main(int) is the correct answer.
2 Comments

IT Professional Development with 5+ years and 3+years IT trainer experience

Hi,If you use int main() it return something..so we mentioned return 0; if you use void main() --void does not return any values.
Comments

JS Academy in Association With Cryptic Technologies Pvt. Ltd.

1. Both type of function can exactly the same, only difference is that return type function return some value so it can be used in expression. Non return type function doesn't return any value so it can't be used in expression. 2. The main is also a function so it can be either return type or non return...
read more

1. Both type of function can exactly the same, only difference is that return type function return some value so it can be used in expression. Non return type function doesn't return any value so it can't be used in expression.

2. The main is also a function so it can be either return type or non return type.

 

Return type main function looks like this...

int main(void) {

 return 0;

}

 

Non return type main function looks like this...

void main(void) {

 

}

 

 

int main(int) {

 // This is incorrect...

}

 

read less
Comments

Whenever you put return type as int, your program always return success code to operating system which is integer value. If you use void as return type of main then your program does not return any indication to operating system. Returning int is good programming practice always. Hope this help....
read more

Whenever you put return type as int, your program always return success code to operating system which is integer value.  If you use void as return type of main then your program does not return any indication to operating system.  Returning int is good programming practice always. 

 

Hope this help. 

 

Regard, 

Sam J

www.myVuniversity.com

read less
Comments

Computer Wizard

int main(void) is the good practice, returning int indicates operating system that programs succesfully finished. If we use main(void) it means main fuction can be called without arguments and main() can be called with arguments.
Comments

Int main(void)--- it can be called only with a function call having no parameters. But int main() can be called by a function with any no.of parameters. int main(void) returns 0 if the program is successfully executed. void main(void) does not return anything. it is a good practice to return some...
read more

Int main(void)--- it can be called only with a function call having no parameters.

But int main() can be called by a function with any no.of parameters.

int main(void)  returns 0 if the program is successfully executed. 

void main(void) does not return anything.

it is a good practice to return some value in any program to know the succesful execution.

 

read less
Comments

I have 17+ years teaching experience. I am good at subject I teach.

int main() by default returns int value. int main(void) will not return anything
Comments

C Language

All four is a valid case. But i think _start not expecting any value so good that return type is void and if we are using command line argument then take argument is good else void is fine.
Comments

View 10 more Answers

Related Questions

What is different between malloc and calloc?
The Diffrences are like-- malloc() takes a single argument (memory required in bytes), while calloc() needs two arguments. Secondly, malloc() does not initialize the memory allocated, while calloc() initializes...
Roopali
What is the best IDE for C and C++ development?
If you're a student then Turbo C++ is best for C and C++ program + inbuilt C/C++ Graphics Function If you're a professional or working then Netbeans for C/C++ or Code:: Blocks is Best.
Balakrishnasingh
Is C++ is next version of C?
This feature looks pretty sweet. This would be great because you wouldn't need getters any more. You could make member variables public; later, if you change your mind, you can turn them into property.
Subham
What is called 'nested loops' in C++?
These are those loops in which one loop executes inside another loop. For example for loop for(int i=1,i=10,i++) { for(int j=1, j<=i,j++) { } } the second loop is the nested for loop.
Harikrishnan
how to use dos.h
First include dos.h header file then use their function. Before use function, you must have knowledge of dos functions and their charactistics
Aman

Now ask question in any of the 1000+ Categories, and get Answers from Tutors and Trainers on UrbanPro.com

Ask a Question

Related Lessons

Advantages of C++ Language
Advantages of C++ - C++ is a profoundly convenient dialect and is frequently the dialect of decision for multi-gadget, multi-stage application advancement. - C++ is a protest situated programming dialect...

Swapping Two Numbers
Q. Swap two numbers using the following function. Complete the function. You won't be allowed to use a temporary variable to swap the two numbers. void swap ( ... ) { /* Swap code goes here */ } ...

C++ Overview
Introduction: C++ is the first object oriented programming language used universally as an advanced version of C language. Many features such as Inheritance, Class & Object, Polymorphism(Function...
N

Namrata Y.

0 0
0

Programing Languages Learning Tricks
You want to learn that new language or library or framework as soon as possible, right? That’s understandable. Fortunately, there are a handful of tips that can help you to better retain all of that...
H

Harshal G.

0 0
0

Set 0 To Kth Bit In A Variable
The following code snippet Set 0 to Kth Bit in an variable #include int UnsetBitValue(int n, int k);int main(){ printf("%d\n\n",UnsetBitValue(255,6)); return 0;}// Set kth bit to zeroint UnsetBitValue(int...

Recommended Articles

Introduction C++ is an excellent programming language and many of the applications are written in C++ language. It has generic, object-oriented & imperative programming features, and also provides facilities for low-level memory manipulation. Successor of C language, it is an OOP (object oriented programming) language...

Read full article >

Almost all of us, inside the pocket, bag or on the table have a mobile phone, out of which 90% of us have a smartphone. The technology is advancing rapidly. When it comes to mobile phones, people today want much more than just making phone calls and playing games on the go. People now want instant access to all their business...

Read full article >

Microsoft Excel is an electronic spreadsheet tool which is commonly used for financial and statistical data processing. It has been developed by Microsoft and forms a major component of the widely used Microsoft Office. From individual users to the top IT companies, Excel is used worldwide. Excel is one of the most important...

Read full article >

Applications engineering is a hot trend in the current IT market.  An applications engineer is responsible for designing and application of technology products relating to various aspects of computing. To accomplish this, he/she has to work collaboratively with the company’s manufacturing, marketing, sales, and customer...

Read full article >

Looking for C++ Language Classes?

Learn from the Best Tutors on UrbanPro

Are you a Tutor or Training Institute?

Join UrbanPro Today to find students near you
X

Looking for C++ Language Classes?

The best tutors for C++ Language Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn C++ Language with the Best Tutors

The best Tutors for C++ Language Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more