Home > Net >  2 output functions in C
2 output functions in C

Time:07-22

so i tried making 2 functions and want to display both outputs and im new to C how do i fix this issue?

Code:

#include <iostream>

namespace first{
    int x = 1;
}
namespace second{
    int x = 2;
}
int main() {

using namespace first;


int x = 0;


std::cout << x << '\n';
std::cout << first::x << '\n';
std::cout << second::x << '\n';

return 0;
}

int lol() {

using namespace std;
using std::cout;

string lolipop = "hello world";

cout << lolipop << '\n';

return 0;

}

i want to display both outputs including hello world and the variables, variable are getting displayed in the output but not the second function the lol one.

CodePudding user response:

You have to call lol function from main.

CodePudding user response:

You need to call lol().

Example:

int lol(); // forward declaration

int main() {
    using namespace first;

    int x = 0;

    std::cout << x << '\n';
    std::cout << first::x << '\n';
    std::cout << second::x << '\n';
    
    lol();                             // calling lol

    return 0;
}
  • Related