Thread: new baby doubt

  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 int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    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.

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    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.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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
    28,413
    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.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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をこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    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.

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, 07: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, 04:41 AM