question on C aptitude

This is a discussion on question on C aptitude within the C Programming forums, part of the General Programming Boards category; hey can anyone explain me the behavior of Code: printf("%d", i=10); should it not print 1 ?...

  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,676
    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,175
    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, 04:23 PM
  3. A question about a question
    By hausburn in forum C++ Programming
    Replies: 3
    Last Post: 04-25-2010, 06:24 AM
  4. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 03:51 PM
  5. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 10:47 PM

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