SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Addict anita_86's Avatar
    Join Date
    Aug 2010
    Location
    Nagpur, India
    Posts
    227
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Curious to know ..

    Hi again!And happy new year to all.Just got to attained an interview and was asked about some c questions.I am not sure I am posting in right forum, but would like to know what does these lines means?Can anyone tell me?
    Code:
    int main()
    {
    int k=printf("Hello");
    return 0;
    exit(10);
    }
    O/P:Hello
    It's easy once you know how...

  2. #2
    Avid Logophile silver trophy
    ParkinT's Avatar
    Join Date
    May 2006
    Location
    Central Florida
    Posts
    2,282
    Mentioned
    180 Post(s)
    Tagged
    4 Thread(s)
    That is C language.
    It would compile into a very small program that outputs "Hello" (without the quotes).

    The last line is NOT part of the program and would throw a compiler error. It appears to be a reference to the output (e.g. O/P)

    All C programs require an "entry point" and the default is called main (which always returns a result code as an integer.
    The routine is enclosed in curly braces. The statement 'printf' is a formatted print function that is part of [one of] the native libraries in C

    Here is an overview reference about the language.
    Don't be yourself. Be someone a little nicer. -Mignon McLaughlin, journalist and author (1913-1983)


    Literally, the best app for readers.
    Make Your P@ssw0rd Secure
    Leveraging SubDomains

  3. #3
    #titanic {float:none} silver trophy
    molona's Avatar
    Join Date
    Feb 2005
    Location
    from Madrid to Heaven
    Posts
    8,023
    Mentioned
    210 Post(s)
    Tagged
    1 Thread(s)
    If you do a google search you can find it yourself...

    You're outputting "Hello" on the screen but since the function main has to return an integer (you said that when you named the function "int main()") you return 0 (meaning that the function has succeed)

    But if the function doesn't work, the exit function will end it up and return a code error 10

    I'm more than happy to help but sometimes I wish that people would use Google a bit.

    Edit: Seems that ParkinT was quicker than me

  4. #4
    SitePoint Addict anita_86's Avatar
    Join Date
    Aug 2010
    Location
    Nagpur, India
    Posts
    227
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok I got it a little bit.Thanks for quick reply.Going line by line, int main() is a function which is integer.And if it returns error, it returns error code 10 and exits the function.Since the functions dosent work,it is returning 0.Im I right?
    It's easy once you know how...

  5. #5
    #titanic {float:none} silver trophy
    molona's Avatar
    Join Date
    Feb 2005
    Location
    from Madrid to Heaven
    Posts
    8,023
    Mentioned
    210 Post(s)
    Tagged
    1 Thread(s)
    Almost there but...No

    If the function main works perfectly, it will print the message on screen and the value returned will be 0.

    If there's an error, the value returned will be 10.

  6. #6
    Avid Logophile silver trophy
    ParkinT's Avatar
    Join Date
    May 2006
    Location
    Central Florida
    Posts
    2,282
    Mentioned
    180 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by molona View Post
    I'm more than happy to help but sometimes I wish that people would use Google a bit.
    I agree and would much rather see a question posed as, "I searched for the answer, found this, but would like a little more clarification from someone with direct experience in this area"
    This is a very helpful community, but there is A LOT to be gained from [even an attempt at] seeking the answer on your own first.
    Last edited by molona; Jan 5, 2012 at 01:14. Reason: adding ending bbcode
    Don't be yourself. Be someone a little nicer. -Mignon McLaughlin, journalist and author (1913-1983)


    Literally, the best app for readers.
    Make Your P@ssw0rd Secure
    Leveraging SubDomains

  7. #7
    SitePoint Addict anita_86's Avatar
    Join Date
    Aug 2010
    Location
    Nagpur, India
    Posts
    227
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks a lot.and the link is very useful.
    Quote Originally Posted by molona View Post
    I'm more than happy to help but sometimes I wish that people would use Google a bit.
    Thats very true.and I will keep it in mind next time
    It's easy once you know how...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •