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

  • SEARCH
  • Home
  • 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 6668285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:01:31+00:00 2026-05-26T03:01:31+00:00

This is very trivial but I am not getting it. shadyabhi@archlinux /tmp $ ./a.out

  • 0

This is very trivial but I am not getting it.

shadyabhi@archlinux /tmp $ ./a.out 
2345
51  <-- **Why?**
3
shadyabhi@archlinux /tmp $ ./a.out 
abhi
98
50  <-- **Why?**
shadyabhi@archlinux /tmp $ cat main.c 
#include <stdio.h>

int main()
{
    char a[10];
    scanf("%s", a);
    printf("%d\n", a[1]);
    printf("%d\n", a[1] - '0');
    return 0;
}
shadyabhi@archlinux /tmp $ 
  • 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-05-26T03:01:31+00:00Added an answer on May 26, 2026 at 3:01 am

    When a[] contains the string "2345" as you’ve entered, then the expression a[1] is the character code for the character '3'. Since you’re using ASCII as the underlying encoding (based on the codes you’re getting, though it’s not strictly mandated by the standard), the characters '0' thru '9' are represented by the decimal values 48 thru 57 (hex 0x30 thru 0x39).

    In other words, you have:

    a[0] = '2'  = 0x32 = 50
    a[1] = '3'  = 0x33 = 51
    a[2] = '4'  = 0x34 = 52
    a[3] = '5'  = 0x35 = 53
    a[4] = '\0' = 0x00 =  0
    

    The ASCII table is:

        | Dec Hex Chr | Dec Hex Chr | Dec Hex Chr | Dec Hex Chr | 
        |   0  00 NUL |  32  20     |  64  40  @  |  96  60  `  | 
        |   1  01 SOH |  33  21  !  |  65  41  A  |  97  61  a  | 
        |   2  02 STX |  34  22  "  |  66  42  B  |  98  62  b  | 
        |   3  03 ETX |  35  23  #  |  67  43  C  |  99  63  c  | 
        |   4  04 EOT |  36  24  $  |  68  44  D  | 100  64  d  | 
        |   5  05 ENQ |  37  25  %  |  69  45  E  | 101  65  e  | 
        |   6  06 ACK |  38  26  &  |  70  46  F  | 102  66  f  | 
        |   7  07 BEL |  39  27  '  |  71  47  G  | 103  67  g  | 
        |   8  08 BS  |  40  28  (  |  72  48  H  | 104  68  h  | 
        |   9  09 HT  |  41  29  )  |  73  49  I  | 105  69  i  | 
        |  10  0A LF  |  42  2A  *  |  74  4A  J  | 106  6A  j  | 
        |  11  0B VT  |  43  2B  +  |  75  4B  K  | 107  6B  k  | 
        |  12  0C FF  |  44  2C  ,  |  76  4C  L  | 108  6C  l  | 
        |  13  0D CR  |  45  2D  -  |  77  4D  M  | 109  6D  m  | 
        |  14  0E SO  |  46  2E  .  |  78  4E  N  | 110  6E  n  | 
        |  15  0F SI  |  47  2F  /  |  79  4F  O  | 111  6F  o  | 
        |  16  10 DLE |  48  30  0  |  80  50  P  | 112  70  p  | 
        |  17  11 DC1 |  49  31  1  |  81  51  Q  | 113  71  q  | 
        |  18  12 DC2 |  50  32  2  |  82  52  R  | 114  72  r  | 
        |  19  13 DC3 |  51  33  3  |  83  53  S  | 115  73  s  | 
        |  20  14 DC4 |  52  34  4  |  84  54  T  | 116  74  t  | 
        |  21  15 NAK |  53  35  5  |  85  55  U  | 117  75  u  | 
        |  22  16 SYN |  54  36  6  |  86  56  V  | 118  76  v  | 
        |  23  17 ETB |  55  37  7  |  87  57  W  | 119  77  w  | 
        |  24  18 CAN |  56  38  8  |  88  58  X  | 120  78  x  | 
        |  25  19 EM  |  57  39  9  |  89  59  Y  | 121  79  y  | 
        |  26  1A SUB |  58  3A  :  |  90  5A  Z  | 122  7A  z  | 
        |  27  1B ESC |  59  3B  ;  |  91  5B  [  | 123  7B  {  | 
        |  28  1C FS  |  60  3C  <  |  92  5C  \  | 124  7C  |  | 
        |  29  1D GS  |  61  3D  =  |  93  5D  ]  | 125  7D  }  | 
        |  30  1E RS  |  62  3E  >  |  94  5E  ^  | 126  7E  ~  | 
        |  31  1F US  |  63  3F  ?  |  95  5F  _  | 127  7F DEL | 
    

    In the second case with "abhi", a[1] is equal to b which, if you examine that table above, is character code 98 decimal ( hex 0x62).

    For the output lines where you subtract '0', that’s actually subtracting the character code for '0', which is decimal 48 or 0x30 hex.

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

Sidebar

Related Questions

I'm sure this is a very obvious question but I'm not getting anywhere with
This might be extremely trivial, and if so I apologise, but I'm getting really
This very simple code gives me tons of errors: #include <iostream> #include <string> int
This very simple code: #include <iostream> using namespace std; void exec(char* option) { cout
I'm sorry for this very newbish question, I'm not much given into web development.
I find this very strange, must be something I'm doing wrong, but still... I'm
It seemed a trivial matter at the beginning but so far I have not
I know this is probably rather trivial but I have had a look at
I suspect this is a very trivial question. I'm writing a PHP script to
This is very trivial question regarding the use of a constructor in C++. I

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.