I'd like to ask you a question about c++ completely beginner switch.

Asked 2 years ago, Updated 2 years ago, 27 views

I'm trying to use a switch statement, but when I compile op, y, it says it's an uninitialized variable, so what's the problem?

switch문 c++

2022-09-22 20:54

1 Answers

In fact, the best way to learn is to learn assemblies.

It is good to understand the problem by learning how stacks are used when calling functions while debugging the executable.

When a function is called, push the parameter of the function and call the call opcode call opcode Push the following address (return address) to the stack. The local variables are then pushed into the stack.

Stack is the space required to call and execute functions, basically memory space with trash values.

If you don't initialize, you can't predict what value there will be. For this reason, uninitialized regional variables are judged by the compiler as errors.

char op = '';
int y = 0;

Please initialize it as shown in .


2022-09-22 20:54

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.