new baby doubt

This is a discussion on new baby doubt within the C Programming forums, part of the General Programming Boards category; can u tell me the diffrence b/w char a='1'; and char a=1; and can u tell me wht it means ...

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    90

    new baby doubt

    can u tell me the diffrence b/w
    char a='1';
    and
    char a=1;
    and can u tell me wht it means
    int i = 0x1234567

    thank u
    sree

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,334
    Print them both and find out?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    20,968
    can u tell me the diffrence b/w
    char a='1';
    and
    char a=1;
    In ASCII, '1' has the value of 49.

    and can u tell me wht it means
    int i = 0x1234567
    The 0x prefix specifies that the number is expressed in hexadecimal, i.e., 0x1234567 == 19088743.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    Super unModrator
    Join Date
    Dec 2007
    Posts
    321
    Quote Originally Posted by cnu_sree View Post
    can u tell me the diffrence b/w
    char a='1';
    and
    char a=1;

    Code:
    char a='1';
    
    printf("%c",a); //prints 1
    Code:
    char a=1;
    printf("%c",a); //prints character with ASCII value 1

  5. #5
    Registered User
    Join Date
    Apr 2008
    Posts
    83

    Hai this is your answers.....

    Quote Originally Posted by cnu_sree View Post
    can u tell me the diffrence b/w
    char a='1';
    and
    char a=1;
    and can u tell me wht it means
    int i = 0x1234567

    thank u
    sree
    Hai Sree,

    char a='1'--> This is the correct way of initialising character & if you print this means you
    will get correct answer 1
    char a=1--> it will give garbage value

    int i=0X1234567-->Storing address directly into varible i

    hope you understood,..

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    20,968
    char a=1--> it will give garbage value
    It is not a garbage value. It so happens that the char with value 1 is not printable.

    int i=0X1234567-->Storing address directly into varible i
    You are mistaken. 0X1234567 is just an int literal.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Registered User
    Join Date
    Apr 2008
    Posts
    83

    hello

    Quote Originally Posted by laserlight View Post
    It is not a garbage value. It so happens that the char with value 1 is not printable.


    You are mistaken. 0X1234567 is just an int literal.
    yes i am sorry it is only Hex representation of Decimal number right??

  8. #8
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,167
    Yes, it's a number in hex format. 0x1 and 1 is the same thing - both numbers (and in this case, also translate to the same base 10 number).
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Doubt in pointer.
    By shwetha_siddu in forum C Programming
    Replies: 5
    Last Post: 03-21-2009, 01:28 AM
  2. Replies: 4
    Last Post: 12-10-2006, 06:08 PM
  3. Doubt abt Storage!
    By kalamram in forum C Programming
    Replies: 1
    Last Post: 04-21-2006, 05:30 AM
  4. Float vars doubt
    By sevensuns in forum C++ Programming
    Replies: 1
    Last Post: 08-01-2004, 07:57 PM
  5. Greatest C++ Doubt
    By vasanth in forum C++ Programming
    Replies: 15
    Last Post: 02-28-2002, 03:41 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21