+ 1

In this program

1.#include<iostream> 2. using namespace std; 3.void printsomething() { 4. cout<<"hello world"; 5.} 6.int main() { 7. printsomething(); 8. return 0; 9.} here the 8th line has no meaning in the sense that even if i remove it or keep it. i always get the same output. why plis help

18th Jul 2017, 7:08 AM
stephen haokip
stephen haokip - avatar
11 ответов
+ 9
i.e void Afunction() { cout << "inside a function" << endl; } const int aGlobal = 5; // outside int main() { cout << "inside main" << endl; aFunction(); return 0; }
18th Jul 2017, 7:24 AM
jay
jay - avatar
+ 7
return 0 will be added automatically by the compiler if it is missing. It is used to return a value to main. which reports to the operating system if the program exited normally or not.
18th Jul 2017, 7:10 AM
jay
jay - avatar
+ 7
you 'should' but only for the main function. If you forget it is added for you
18th Jul 2017, 7:14 AM
jay
jay - avatar
+ 2
yup it will add return 0 explicitly oops I'm late . Nice ans @jay
18th Jul 2017, 7:11 AM
Nirmal Kumar Bhakat
Nirmal Kumar Bhakat - avatar
+ 2
jay does that mean that i always need to put return 0; everytime in my codes.
18th Jul 2017, 7:12 AM
stephen haokip
stephen haokip - avatar
+ 2
whatever enclosed within the curly braces {} belongs to the respective function or the class (means is the inner side ) whereas outside the braces gives u the outer side of the function or class
18th Jul 2017, 7:18 AM
Nirmal Kumar Bhakat
Nirmal Kumar Bhakat - avatar
+ 1
nope even if u dont the compiler will do it for you
18th Jul 2017, 7:13 AM
Nirmal Kumar Bhakat
Nirmal Kumar Bhakat - avatar
+ 1
ok thanks
18th Jul 2017, 7:14 AM
stephen haokip
stephen haokip - avatar
+ 1
jay and nirmal plis tell me what is inside and outside of a function or class. is it the inner side enclosed by the curly braces.
18th Jul 2017, 7:16 AM
stephen haokip
stephen haokip - avatar
+ 1
thank q
18th Jul 2017, 7:19 AM
stephen haokip
stephen haokip - avatar
+ 1
thanks jay
18th Jul 2017, 7:39 AM
stephen haokip
stephen haokip - avatar