Thread: can you solve this per

  1. #1
    kotin
    Join Date
    Oct 2009
    Posts
    132

    can you solve this per

    while executing below programs i getting same output .anyone can help me?

    Code:
    #include<stdio.h>
    int main()
    {
    char ch='-1';
    printf("%d \n",ch);
    return 0;
    }
    Code:
    #include<stdio.h>
    int main()
    {
    char ch='-1';
    printf("%d \n",ch);
    return 0;
    }

    i getting output as 49 in both programs . i look for your suggestions

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    go to:

    Commercial interests have taken over asciitables.com, but google ascii and d/l a table.

    A 1 does not have the value of 1 inside your computer. It has the value of 1 only after you specify that it is a number. Same with char's.
    Last edited by Adak; 11-15-2009 at 10:56 PM.

  3. #3
    kotin
    Join Date
    Oct 2009
    Posts
    132
    hi adak,

    actuvally is showing same output (49) for char ch="-1" and char ch="1". thats y i little bit consfusing.can u give explanation on this?

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Both programs are identical. Why would you expect to get different output between the two? You should compile with warnings on. '-1' isn't a single character.


    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    kotin
    Join Date
    Oct 2009
    Posts
    132
    hi quzah,

    ya i understnd your point .

    from above conversion i understnd below point

    so if i give '-1' , it compiling with waring and it take right hand side value '1' as a input.

    thats why it showing asci value of charcter '1'=49 .

    so when i give char ch='-1' or char ch='ab' , compiler compile with warning and it taken values on right hand side value ('1' ,'b').

    am i right

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can anyone solve this for me? (look inside)
    By johnsonswww in forum C Programming
    Replies: 10
    Last Post: 03-02-2009, 11:24 AM
  2. No clue how to make a code to solve problems!
    By ctnzn in forum C Programming
    Replies: 8
    Last Post: 10-16-2008, 02:59 AM
  3. any1 can solve this
    By ajoi24 in forum C++ Programming
    Replies: 15
    Last Post: 08-10-2008, 07:47 AM
  4. Replies: 2
    Last Post: 04-25-2005, 11:59 AM
  5. Help to solve this problem
    By Romashka in forum C++ Programming
    Replies: 3
    Last Post: 04-16-2002, 09:32 AM