Click here to Skip to main content
16,013,548 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello guys this is my second question and it is quit foolish of me, but I am not getting it so please help me.
In the following program I know the output but I am confused how it is done.
Program 1
XML
#include<stdio.h>
#include<conio.h>
main()
{
      int x=2;
      if(x=3)
      {
      printf("%d",x++);
      }
      else
      {
      printf("%d",--x);
      }
getch();
}


The output of the following program is 3 but how it comes, I don't get it.

Program 2
XML
#include<stdio.h>
#include<conio.h>
int main()
{
      int x=01234;
      printf("The result is  %d",x);
      return 0;
      getch();
}


The Output of the following program is 668 and don't get it too.
So please give me some hint.

Thanks guys...:)
Posted
Comments
VISH_a_CODE 10-Dec-12 1:09am    
Sory for that but I get it now...:)

In the program 1 the x=3 assignment is hidden inside the if statement. It is a common mistake by the programmers to use assignment (=) operator in place of equal (==) operator.

In the program 2, when you assign a value to variable x you use an octal form (when a numeric literal begins with 0 it is an octal number)
 
Share this answer
 
This is realy a bad question. For what purpose the code is write? Are you test members in Code project? Listen program1, there is no comparison in if condition. ie, watch your code
C++
if( x = 3 )
. Actualy here value 3 is assigned to x. no comparison is done.
Don't post this type of question in code project. You can debug the code and ensure what happend.
 
Share this answer
 
Comments
VISH_a_CODE 10-Dec-12 1:09am    
Sory for that but I get it now...:)
[no name] 10-Dec-12 1:25am    
Iam said that for your better future. Take it as a feedback :-)
In the program 1 the x=3 assignment is hidden inside the if statement. It is a common mistake by the programmers to use assignment (=) operator in place of equal (==) operator.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900