Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8746651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:13:41+00:00 2026-06-13T12:13:41+00:00

what does return 4 return 2 return 6 in this code really returning is

  • 0

what does return 4 return 2 return 6 in this code really returning is not making sense to me may someone explain to me what they return,i saw this code on stack flow someone wanted an explanation on infix and prefix convertion

#include<stdio.h> 
#include<conio.h> 
#include<string.h> 
#define MAX 20 

char stack[MAX]; 
int top = -1; 
char pop(); 
void push(char item); 

int prcd(char symbol) 
{ 
    switch(symbol) 
    { 
    case '+': 
    case '-': 
        return 2; 
    case '*': 
    case '/': 
        return 4; 
    case '^': 
    case '$': 
        return 6; 
    case '(': 
    case ')': 
    case '#': 
        return 1; 
    } 
} 

int isoperator(char symbol) 
{ 
    switch(symbol) 
    {
    case '+': 
    case '-': 
    case '*': 
    case '/': 
    case '^': 
    case '$': 
    case '(': 
    case ')': 
        return 1; 
    default: 
        return 0; 
    } 
} 

void convertip(char infix[],char prefix[]) 
{ 
    int i,symbol,j=0; 
    char test[MAX]; 

    infix=strrev(infix); 
    stack[++top]='#'; 

    for(i=0;i<strlen(infix);i++) 
    { 
        symbol=infix[i]; 
        if(isoperator(symbol)==0) 
        { 
            prefix[j]=symbol; 
            j++; 
        }
        else 
        { 
            if(symbol==')') 
            { 
                push(symbol); 
            } 
            else if(symbol=='(') 
            {    
                while(stack[top]!=')') 
                { 
                    prefix[j]=pop(); 
                    j++; 
                }    

                pop();//pop out (. 
            } 
            else 
            { 
                if(prcd(symbol)>prcd(stack[top])) 
                { 
                    push(symbol); 
                }
                else 
                { 
                    while(prcd(symbol)<=prcd(stack[top])) 
                    { 
                        prefix[j]=pop(); 
                        j++; 
                    } 
                    push(symbol); 
                }//end of else. 
            }//end of else. 
        }//end of else. 
    }//end of for. 

    while(stack[top]!='#') 
    { 
        prefix[j]=pop(); 
        j++; 
    } 

    prefix[j]='\0';//null terminate string. 
    prefix=strrev(prefix); 

} 

int main() 
{ 
    char infix[20],prefix[20]; 
    //clrscr(); 
    printf("Enter the valid infix string:\n"); 
    gets(infix); 
    convertip(infix,prefix); 
    printf("The corresponding prefix string is:\n"); 
    puts(prefix); 
    getch(); 

    return 0; 
} 

void push(char item)
{ 
    top++; 
    stack[top]=item; 
} 

char pop() 
{ 
    char a; 
    a=stack[top]; 
    top--; 
    return a; 
} 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T12:13:42+00:00Added an answer on June 13, 2026 at 12:13 pm

    This code might interpret numerical terms, like. 17 + 3 * 8. To calculate this properly, the code must determine to first take the * and then the +. The order of evaluation is set by the precedence rules: * and / come before + and -.

    The return statements look like some precedence code.

    • (, ), #: return 1
    • +, -: return 2
    • *, /: return 4
    • ^, $: return 6

    (, ) and # have lowest precedence. After that + and – have next lowest precedence. Then follows * and /. Highest precedence is for ^ and $.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is probably a quicky. Why does this code not return anything? import java.util.Scanner;
Why does this code always return 0? var possibleMatches = new Array(); $.getJSON('getInformation.php', function(data)
can someone please help me. why does this return an error: Dim stuff As
NHibernate really does not seem to like returning a ReadOnlyCollection, depsite me having implemented
I need help here. My jQuery code does not return the submit button name
Why does this return 23 rows (the right amount): select users.user_id, users.fname, users.lname, stars.stars,
CGFloat* colors = CGColorGetComponents(hsbaColor.CGColor); Does this return a float, or an array of floats?
Why does this script return a pair of nulls? I'm using SQL Server 2008,
Why does this regex return true? Regex.IsMatch(العسكرية, العسكري) I googled and nothing came up.
Why does this simple web service refuse to return JSON to the client? Here

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.