8 Replies - 332 Views - Last Post: 18 April 2013 - 09:00 PM Rate Topic: -----

#1 dharma19  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 17-April 13

if condition

Posted 17 April 2013 - 11:50 PM

int a=0,b=20,c=1;
if(a,b,c)   //what is the meaning of this type of condition?
 printf("hai");
else
 printf("hello");



output is: hai

how is this will execute i need clear explanation

This post has been edited by Atli: 18 April 2013 - 12:36 AM
Reason for edit:: Use [code] tags when posting code.

Is This A Good Question/Topic? 0
  • +

Replies To: if condition

#2 kai_itz me  Icon User is offline

  • D.I.C Head

Reputation: 28
  • View blog
  • Posts: 159
  • Joined: 03-August 12

Re: if condition

Posted 18 April 2013 - 12:25 AM

i wonder why you are not getting any error.

i don't see your (if condition) making any sense. There is no condition for else not even for if.

if you even left your if(condition) empty it will still print "hai" by default.


This post has been edited by kai_itz me: 18 April 2013 - 12:35 AM

Was This Post Helpful? 0
  • +
  • -

#3 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3716
  • View blog
  • Posts: 5,976
  • Joined: 08-June 10

Re: if condition

Posted 18 April 2013 - 01:06 AM

Wikipedia has a pretty good description of what's going on there:

Quote

In the C and C++ programming languages, the comma operator (represented by the token ,) is a binary operator that evaluates its first operand and discards the result, and then evaluates the second operand and returns this value (and type).

http://en.wikipedia..../Comma_operator
Was This Post Helpful? 2
  • +
  • -

#4 kai_itz me  Icon User is offline

  • D.I.C Head

Reputation: 28
  • View blog
  • Posts: 159
  • Joined: 03-August 12

Re: if condition

Posted 18 April 2013 - 03:08 AM

WOW,i learn something new, thanks @Atli

i apologize for what i told you earlier @Dharma19
Was This Post Helpful? 0
  • +
  • -

#5 dharma19  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 17-April 13

Re: if condition

Posted 18 April 2013 - 03:14 AM

View Postkai_itz me, on 18 April 2013 - 12:25 AM, said:

i wonder why you are not getting any error.

i don't see your (if condition) making any sense. There is no condition for else not even for if.

if you even left your if(condition) empty it will still print "hai" by default.




hi
thank you for your reply
but if you put if(condition) is empty ,in compilation time it shows expression syntax error
Was This Post Helpful? 0
  • +
  • -

#6 dharma19  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 17-April 13

Re: if condition

Posted 18 April 2013 - 03:23 AM

View PostAtli, on 18 April 2013 - 01:06 AM, said:

Wikipedia has a pretty good description of what's going on there:

Quote

In the C and C++ programming languages, the comma operator (represented by the token ,) is a binary operator that evaluates its first operand and discards the result, and then evaluates the second operand and returns this value (and type).

http://en.wikipedia..../Comma_operator




thank you for your valuable reply
i have another one doubt
ie: what is the difference between run time execution and compile time execution?
make me clear by using some example
Was This Post Helpful? 0
  • +
  • -

#7 kai_itz me  Icon User is offline

  • D.I.C Head

Reputation: 28
  • View blog
  • Posts: 159
  • Joined: 03-August 12

Re: if condition

Posted 18 April 2013 - 03:49 AM

i got it from somewhere
The difference between compile time and run time is an example of what pointy-headed theorists call the phase distinction. It is one of the hardest concepts to learn, especially for people without much background in programming languages. To approach this problem, I find it helpful to ask

What invariants does the program satisfy?
What can go wrong in this phase?
If the phase succeeds, what are the postconditions (what do we know)?
What are the inputs and outputs, if any?
Compile time

1.The program need not satisfy any invariants. In fact, it needn't be a well-formed program at all. You could feed this HTML to the compiler and watch it barf...
2.What can go wrong at compile time:
Syntax errors
Typechecking errors
(Rarely) compiler crashes

3.If the compiler succeeds, what do we know?
The program was well formed---a meaningful program in whatever language.
It's possible to start running the program. (The program might fail immediately, but at least we can try.)
4.What are the inputs and outputs?
Input was the program being compiled, plus any header files, interfaces, libraries, or other voodoo that it needed to import in order to get compiled.
Output is hopefully assembly code or relocatable object code or even an executable program. Of if something goes wrong, output is a bunch of error messages.
Run time

1.We know nothing about the program's invariants---they are whatever the programmer put in. Run-time invariants are rarely enforced by the compiler alone; it needs help from the programmer.

2.What can go wrong are run-time errors:

Division by zero
Deferencing a null pointer
Running out of memory
Also there can be errors that are detected by the program itself

Trying to open a file that isn't there
Trying find a web page and discovering that an alleged URL is not well formed

3.If run-time succeeds, the program finishes (or keeps going) without crashing.
4.Inputs and outputs are entirely up to the programmer. Files, windows on the screen, network packets, jobs sent to the printer, you name it. If the program launches missiles, that's an output, and it happens only at run time :-)

This post has been edited by kai_itz me: 18 April 2013 - 03:56 AM

Was This Post Helpful? 0
  • +
  • -

#8 dharma19  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 17-April 13

Re: if condition

Posted 18 April 2013 - 08:45 PM

thank you for your reply,
in compile time what happen in macro definition?
ie #define SIZE 10
what actually happen in this macro during compile time and run time?

This post has been edited by GunnerInc: 18 April 2013 - 08:53 PM
Reason for edit:: Quote be gone

Was This Post Helpful? 0
  • +
  • -

#9 GunnerInc  Icon User is offline

  • "Hurry up and wait"
  • member icon




Reputation: 858
  • View blog
  • Posts: 2,279
  • Joined: 28-March 11

Re: if condition

Posted 18 April 2013 - 09:00 PM

http://en.wikipedia..../C_preprocessor

What #define SIZE 10 does, is it tells the preprocessor that anywhere it sees SIZE in your code, to replace it with 10. This makes code more readable and easier to modify.

If you are creating, let's say a window, instead of using 324 as the width everywhere in your code, you would do:
#DEFINE WINDOW_WITDH 324 and use WINDOW_WIDTH. Now in the future, if you change your window width (or whatever), you don't need to find and replace all occurrences of 324, instead, you just change the define value.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1