- 3
[SOLVED ]Im unable to execute the code
3 Respostas
+ 3
you cannot declare variable inside an if-else statement:
int pop(){
int result;
if(stack[top]==empty)
return stack_empty;
else
result=stack[top];
top--;
return (result);
}
+ 1
stack[top] == empty will compare the stack element at index 'top' with empty (instead of the stack element counter).
"you cannot declare variable inside an if-else statement"
In this context 'result' cannot be declared in the if-else statement because it's returned by the function. I'd personally drop the temp variable (and maybe even reduce it down to a one-liner).
return (top > empty) ? stack[--top] : stack_empty;
Source: https://code.sololearn.com/cA136A7a1694
0
visph Seems to be simple one
Thanks ❤️