Message from C, C++ talks

July 2019

— I know that it's an if statement but what does it evaluates to?

— The comma operator returns the last operand. It's been used for a lot of (doubtful) things. It even led to some library implementors to think about it's overloading (yes, you can overload the comma operator)

Message permanent page

— Was this for me?

— Nope


I tried to explain it earlier

(2,1,0) returns zero
i=0 returns zero
if(0) evaluates as false
And you got Hello from that branch

— How does it work

— Which step?

— 3 params in one parantheis

— Oh, wait sry, I thought it's you asked the initial question :)

— Https://

— Its comma operator... Google it

— Comma can be used as an operator too ...

— If statement gets executed only when it gets its condition true(i.e 1 ) so by initialisation i =1, the if statement will be executed ....if u assign any other value then non zero value it will get executed ...but when u assign 0 gets false

Message permanent page

— Https://
Can somebody help me with uploading this problem's solution in spoj. I am fairly new in competitive programming .In this binary search problem my code is running fine, outside in my local compiler but I am unable to know why my code is not accepted by the spoj. Help me out. Here is my code: #include <bits/stdc++.h>
using namespace std;

int arr[100],numberOfElemenets;

int BinarySearch(int x){
int mid,left=0,right=numberOfElemenets;
if(arr[mid]==x) return mid;
else if (arr[mid]>x) right = mid-1;
else left = mid +1;
return -1;

int main() {
int n;
cout<<"Enter the number of elements: ";
cin >> n;
for(int i=0 ; i<n ; ++i){
for(int i=0 ; i<n ; ++i){
cout<<arr[i]<<" ";
cout<< endl;
cout<<"The elements is present at :"<<BinarySearch(2)<<endl;
cout<<"The elements is present at :"<<BinarySearch(4)<<endl;
cout<<"The elements is present at :"<<BinarySearch(8)<<endl;


Message permanent page

— **Any value except than zero is true