its a simple question

This is a discussion on its a simple question within the C Programming forums, part of the General Programming Boards category; Hi in the following condition: if (x>0) { ... } the curly brackets are executed if the value of x ...

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    9

    Unhappy its a simple question

    Hi

    in the following condition:

    if (x>0) { ... }

    the curly brackets are executed if the value of x is above 0.

    What is the situation if you have just:

    if(x){ ... } ?

    Does it mean, 'if the value of x IS 0 then execute the code in the brackets' or does it mean the oposite?

    Stupid question I know but ....

    Thanks
    Buck

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    247
    Hi
    if(x > 0) {....} /* this will perform process if x is greater than zero*/

    if(x) {....} /*this will perform process if x is not equal to zero...but will perorm when x is less than zero i.e. ( - 1 )*/

    when there is only one operand in the comparison...in C true equates to a non zero value and zero is false....therefore in second if statement if(x) means if x is not equal zero (true) process will perform....also curlies are optional when there is only one operation is required after comparison statement...
    Code:
      if(x)
        printf("%d", x);
    
    /*when 2 or more*/
       if(x)
       {
         printf("%d", x);
         do something else;
       }
    hoping to be certified (programming in c)
    here's the news - I'm officially certified.

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    9
    Thanks bigtamscot

    Wood for the trees.....

    Buck71

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple question regarding variables
    By Flakster in forum C++ Programming
    Replies: 10
    Last Post: 05-18-2005, 08:10 PM
  2. Simple class question
    By 99atlantic in forum C++ Programming
    Replies: 6
    Last Post: 04-20-2005, 11:41 PM
  3. Simple question about pausing program
    By Noid in forum C Programming
    Replies: 14
    Last Post: 04-02-2005, 08:46 AM
  4. simple question.
    By InvariantLoop in forum Windows Programming
    Replies: 4
    Last Post: 01-31-2005, 11:15 AM
  5. simple fgets question
    By theweirdo in forum C Programming
    Replies: 7
    Last Post: 01-27-2002, 05:58 PM

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