Thread: Basic C programming 3

  1. #1
    Registered User
    Join Date
    Jun 2012
    Posts
    21

    Basic C programming 3

    #include<stdio.h>

    #include<math.h>
    int main(x)
    {
    int y,z;


    y=-~x;
    z=printf("hi\r");
    printf("%d",x = pow(z,y));

    }


    output :- 9i

    Please explain how 'x' is taking some int value
    Last edited by vivekgupta; 06-12-2012 at 04:51 PM.

  2. #2
    Registered User
    Join Date
    Sep 2007
    Posts
    1,012
    Please use code tags.

    Where are you getting this horrible code? main() is declared incorrectly, but what's probably happening is that “x” is being passed the argument count (what is traditionally called argc). Since this is a pre-ANSI declaration, and no type is given for “x”, it defaults to int, which is why it'd be taking "some int value".

    I highly recommend that, if you're actually interested in learning C, you stop going to whatever site/reading whatever book is giving you this junk. It's worthless.

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by cas
    I highly recommend that, if you're actually interested in learning C, you stop going to whatever site/reading whatever book is giving you this junk. It's worthless.
    Yes, please. You've already been told this before. Persisting in learning rubbish is futile. (Okay, it is not completely rubbish, but the trivia that this involves just hinders your useful learning.)
    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
    Registered User
    Join Date
    Dec 2011
    Posts
    795
    Can't tell if crossposter, or just copied from here. FFS, you need to learn the basics of C before you even touch bitwise operations.

    Also, why are all of your topics pretty much:
    *some ........ed-up code*

    output :- *some undefined error*

    Please explain *something obvious*

  5. #5
    Registered User
    Join Date
    Jun 2012
    Posts
    21
    So please say which book should i read to learn C from 'very basic' to a better and better level ?? And Should I learn C++ because my friend told me to learn C++ direct
    Last edited by vivekgupta; 06-13-2012 at 03:35 AM.

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Here's a list of things to watch out for when choosing a book. If you see any of these, put it down and find another book.
    The title contains adjectives like "guru" or "dummies"
    The title mentions a specific compiler like "TurboC"
    The title mentions a timescale like "21 days" (see Teach Yourself Programming in Ten Years)

    Skim the code examples in the book. If you see any of these, put it down and walk away.
    void main()
    gets(buffer), unless it is a single example telling you NOT to use it (which would be a positive sign)
    fflush(stdin)

    The author is "herbert schildt", Showing 1 - 12 of 154 Results
    For those who can't do maths, that's one new book or edition every 3 weeks for a solid decade!
    "written by" should be read as "cobbled together by an army of ghost writers, then rubber stamped by HS"
    bullschildt

    This site has a number of reviews
    ACCU :: Book Reviews Search
    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.

  7. #7
    Registered User
    Join Date
    Sep 2007
    Posts
    1,012
    So please say which book should i read to learn C from 'very basic' to a better and better level ??
    In addition to what Salem said, I will specifically recommend against Let Us C by Yashavant Kanetkar; this book is ridiculously bad. I mention it only because it is a popular book in India and your username implies that you might be Indian.

    As for C++, you should learn it if you want to learn it.

  8. #8
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    Quote Originally Posted by cas View Post
    In addition to what Salem said, I will specifically recommend against Let Us C by Yashavant Kanetkar; this book is ridiculously bad. I mention it only because it is a popular book in India and your username implies that you might be Indian.
    ....that's putting it lightly.
    It proudly portrays every sort of code that should be specifically warned against.

    (I saw a recent version with a chapter on Linux Programming, though ...which wasn't written so badly.)

  9. #9
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    How did YK get Turbo C to run on Linux???

  10. #10
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    Quote Originally Posted by rags_to_riches View Post
    How did YK get Turbo C to run on Linux???
    ... the code in that chapter is 'standard' code and has a quite different style than the rest of the book.
    (Could be written by someone else..)

  11. #11
    Registered User R41D3N's Avatar
    Join Date
    Mar 2012
    Location
    ...Beyond Infinity, Behind a KeyBoard...
    Posts
    29
    lol Let Us C by YK can be used as a book to refer to so as to know how not to code :P ...

    For C++, you dont need to start out with C. If your final aim is C++, better you start of directly with it than going about in circles ...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Basic C programming -1
    By vivekgupta in forum C Programming
    Replies: 29
    Last Post: 06-11-2012, 03:26 PM
  2. Basic C programming help
    By jonny0503 in forum C Programming
    Replies: 3
    Last Post: 01-13-2012, 01:00 PM
  3. Basic c programming help
    By benrogers in forum C Programming
    Replies: 12
    Last Post: 01-24-2011, 05:01 PM
  4. basic C programming help
    By helfone in forum C Programming
    Replies: 3
    Last Post: 10-22-2007, 09:54 AM
  5. Basic Programming
    By plexy1 in forum C Programming
    Replies: 2
    Last Post: 09-05-2001, 02:03 PM