Harshani Fernando Harshani Fernando - 3 months ago 11
C Question

Can we put a char digit into an int Stack in C programming language?

We're given a char arithmetic expression and we should put the operands into an int stack and solve the expression with the operator and get the answer. Is it possible passing a character into a integer stack and get the answer?

alk alk
Answer

Is it possible passing a character into a integer

Yes, this works:

#include <stdio.h>

void print_me(signed char c; int i)
{
  printf("'%c' = %d\n", c, i);
}

int main(void)
{
  signed char c = 'A';
  int i = c;

  print_me(c, i);

  ...

Assuming ASCII character encoding this would print:

'A' = 65