+ 3

function call in another function

I wanna know, can call a function inside another function in c++? if (yes) than how i can tell the program in C++ to understand i declared a data in in other line after function? for example function () { cout<<a;} main { int a=2;} error - 'a' is not declared

26th Nov 2018, 3:50 PM
Abolhasan Ashori
Abolhasan Ashori - avatar
2 odpowiedzi
+ 6
It should be like that, void function (int parameter) // line1 { cout<< parameter; } int main () { int a=2; function (a) // line 8 } You can change the parameter's data type into whatever you want (char, float, double or your own data type like structures classes so on) and make some changes or print them as I did. Edit: Your program needs to take the variable as parameter shown in the example above (in line 1). and then you need to pass it to function inside main function (in line 8)
26th Nov 2018, 4:28 PM
Mustafa K.
Mustafa K. - avatar
+ 3
You need to add a parameter or if you don' want to add parameter declare a as global variable
28th Nov 2018, 3:51 AM
Linda
Linda - avatar