in DS
357 views
0 votes
0 votes

GATE 2007 QUESTION(DOUBT)

https://gateoverflow.in/3465/gate2007-it-32

Guys in this question %c is there in printf.......and ans is 25.....but why the ASCII value of 25 is not printed????? As %c is used here. Kindly help where I am getting wrong??

in DS
357 views

2 Comments

verified... it is wrong in GATE itself...

 

  #include <stdio.h>
           #define EOF -1
           void push (int); /* push the argument on the stack */
           int pop  (void); /* pop the top of the stack */
           void flagError ();
           int main ()
          {         int c, m, n, r;
                     while ((c = getchar ()) != EOF)
                    { if  (isdigit (c) )
                               push (c-'0');
                     else if ((c == '+') || (c == '*'))
                    {          m = pop ();
                                n = pop ();
                                r = (c == '+') ? n + m : n*m;
                                push (r);
                      }
                      else if (c != ' ')
                               flagError ();
             }
              printf("%d", pop ());
}

 

coming to your question

Guys in this question %c is there in printf.......and ans is 25.....but why the ASCII value of 25 is not printed?????

when %c is used.... character printed, when %d is used digits ( ASCII values in case of characters ) printed

0
0
Thanx...got it
0
0

Please log in or register to answer this question.

Related questions