if there is a warning case bypasses initialization of a local variable in a C + + program, what is the solution to solve it? please help

Recommended Answers

All 3 Replies

Give the variable a value when you create it.

You need to post the code that produces the error. But I have seen it when I tried to declare a variable within one of the case statements without usine brackets { and }

switch(item)
{
    case 1:
       int x; // this will produce that warning

The solution is to use brackets

    switch(item)
    {
        case 1:
        {
           int x; 

        }

That's one solution to the problem--one solution because there are a lot of ways you can avoid this warning.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.