Thread: question on C aptitude

  1. #1
    Registered User
    Join Date
    Dec 2010
    Posts
    21

    question on C aptitude

    hey can anyone explain me the behavior of

    Code:
    printf("%d", i=10);
    should it not print 1 ?

  2. #2
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    Why would you think it would print 1? I don't see a 1 anywhere in there, except as part of the number 10.

  3. #3
    Registered User
    Join Date
    Dec 2010
    Posts
    21
    i think the evaluation i=10 will return true ie 1

  4. #4
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    i == 10 evaluates to 1 (if i is indeed equal to 10), but i = 10 evaluates to 10 (equality vs. assignment).
    Last edited by itsme86; 01-10-2011 at 05:53 PM. Reason: Added necessity for i being equal to 10
    If you understand what you're doing, you're not learning anything.

  5. #5
    Registered User
    Join Date
    Dec 2010
    Posts
    21
    oh So thats the difference ..
    Thanks a lot

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A question on C aptitude
    By devilofwar in forum C Programming
    Replies: 2
    Last Post: 12-13-2010, 02:02 PM
  2. Question bout my work
    By SirTalksAlots in forum C Programming
    Replies: 4
    Last Post: 07-18-2010, 03:23 PM
  3. A question about a question
    By hausburn in forum C++ Programming
    Replies: 3
    Last Post: 04-25-2010, 05:24 AM
  4. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 02:51 PM
  5. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM