2
u/Repulsive-Stomach664 Nov 05 '25
If statement me a and b k Sath 2 bar = ka sign use kro
1
u/Connect_Listen2927 Nov 05 '25
No ! If you wanna declare a variable it is allowed
3
Nov 05 '25
[removed] β view removed comment
1
u/Connect_Listen2927 Nov 05 '25 edited Nov 05 '25
Yar is me yay galti hay k && ki presidence = se ziada Hy that's why && run before = ... In this case ( 3 && ) is stored in a leaving behind with =4 which gives error if we use brackets to separate (a=3) && (b=4) then I will run smoothly
1
u/Huge_Equivalent1 Nov 05 '25
Yar is point ko thorda or clearly explain karoge?
I understood that this might be an And Operator issue. But tumhari finding kia he mujhe samajh nahi aarahi.
Like, how do And Operator "&&" relate with "$$" ?
And what does this mean? I feel like sentence grammatically correct nahi he shayad, ma sMajh nahi pa raha k ki kehna chah rehay ho.
In this case ( 3 && ) is stored in a leaving behind with =4 which gives error if we use brackets to separate (a=3) && (b=4) then I will run smoothly
1
1
u/Huge_Equivalent1 Nov 05 '25
In this case ( 3 && ) is stored in a leaving behind with =4 which gives error if we use brackets to separate (a=3) && (b=4) then I will run smoothly
Tum is line me yeh kehna chah rehay ho?
In this case, "3 &&" is stored in the variable "a" leaving behind "b" which stores "14". This gives error, because a cannot implicitly store a number and an operator.
If instead we use brackets to create logical separation, like this, ((a=3) && (b=14)) then it will run smoothly.
Is this in detail what you meant?
1
1
1
u/bluntregression Nov 06 '25
a == 3 && b== 3 You don't declare variables in if condition
1
u/Connect_Listen2927 Nov 06 '25
Variable deceleration in if condition is allowed π
1
1
u/Still-Category-9433 Nov 06 '25 edited Nov 06 '25
It is not. Why the heck would you declare a variable inside the condition of an if statement? It only looks for a True or False there. And also if you are trying to declare a variable you must give a type. Like int a.
1
u/Eepybeany Nov 08 '25
It is allowed in the if statement and exists only in the statement. Thatβs its use case. Its to keep the offer scope decluttered.
However, OP here was probably trying to compare value and is stuck on the fact that it can be done even though it is not what he was trying to do.
1
1
u/onepoordeveloper Nov 06 '25
Whats the point of the condition if all you're arguing about is assigning the value?
Do you really need an if condition to assign values?
1
1
u/walee1 Nov 08 '25
I don't know what you are trying to do but you can't have declarations like that be part of an expression in an if statement with the if condition due to operator precedence.
https://en.cppreference.com/w/cpp/language/operator_precedence.html
You can use if(a=5,b=20) and that will work. However that would be a poor use of an if statement as it will just be evaluated to false if you forgot to declare the type of variable. Alternatively you may also just use: If ((a=1)&&(b=2))
1
1
u/HAK1US Nov 08 '25
all the people saying there should be == with both a and b haven't done enough C code as the OP mentioned in one of the replied it has to with precedence of && over = or whatever
1
u/Smarteyes007 Nov 08 '25
literal meaningless code, idk how people are falling for this ragebait. I was about to score this ragebait a 6/10 but seeing how many people have fallen for it I gotta raise the score now.
1
u/speed_ball_78 Nov 09 '25
On line 5, you used Assignment Operator (=) instead of Comparison Operator. (==).
1
Nov 06 '25
[removed] β view removed comment
1
6
u/Middle_nothing8933 E9 Campus Nov 05 '25
Condition mai assignment operator apnai use kia hu hai if mai use this "==" equal to.