{    int a,b,c,d,e; float percentage;  cout&lt;&lt;"marks= "; cin&gt;&gt;a; cin&gt;&gt;b; cin&gt;&gt;c;  cin&gt;&gt;d; cin&gt;&gt;e;  percentage= (a+b+c+d+e)/5; cout&lt;&lt;"Percentage= "&lt;&lt;percentage&lt;&lt;endl;  if (percentage&lt;40) cout&lt;&lt;"fail";  else if (percentage&gt;=40,percentage&lt;=49) cout&lt;&lt;"third division";  else if (percentage&gt;=50,percentage&lt;=59) cout&lt;&lt;"second division";  else if (percentage&gt;=60) cout&lt;&lt;"first division";  }   When i submit this to my lecturer, he said that it is theoretically wrong to use comma in the condition, and is suppose to be &amp;&amp;. However, I have successfully run this program. Can anyone explain to me?
1679
What does the , operator do in C?
12536
I was working with a new C++ developer a while back when he asked the question: "Why can't variable names start with numbers?"  I couldn't come up with an answer except that some numbers can have text in them (123456L, 123456U) and that wouldn't be possible if the compilers were thinking everything with some amount of alpha characters was a variable name.  Was that the right answer?  Are there any more reasons?  string 2BeOrNot2Be = "that is the question"; // Why won't this compile?
3011
Ok I hope I am mising something here as I really don't want this to be a bug.   The following piece of code returns 2. Per my understanding of the ceiling functionality, the result should be 3 because 7/3 is roughly 2.33333 and the ceiling should return 3.   Is this a bug or am I missing something? Thanks.   Integer pageNumber = (Integer) Math.ceil(7/3);   This returns 2 and not 3 as expected.   It works fine on other input. For example:  Integer pageNumber = (Integer) Math.ceil(8/5);   This returns 2 as expected.
12628
Is there a benefit to using one over the other? In Python 2, they both seem to return the same results:  &gt;&gt;&gt; 6/3 2 &gt;&gt;&gt; 6//3 2
66958
I want to do:  int a = 255;  cout &lt;&lt; a;   and have it show FF in the output, how would I do this?
37655
In Bash, two integers can be compared using conditional expression     arg1 OP arg2      OP is one of -eq, -ne, -lt, -le, -gt, or -ge. These   arithmetic binary operators return true if arg1 is equal to, not equal   to, less than, less than or equal to, greater than, or greater than or   equal to arg2, respectively. Arg1 and arg2 may be positive or negative   integers.   or arithmetic expression:     &lt;= &gt;= &lt; &gt; comparison      == != equality and inequality   Why do we have two different ways for comparing two integers? When to use which?  For example, [[ 3 -lt 2 ]] uses conditional expression, and (( 3 &lt; 2 )) uses arithmetic expression. Both returns 0 when the comparison is true  When comparing two integers, can these two methods always be used interchangeably? If yes, why does Bash have two methods rather than one?
66237
I have seen some very weird for loops when reading other people's code. I have been trying to search for a full syntax explanation for the for loop in C but it is very hard because the word "for" appears in unrelated sentences making the search almost impossible to Google effectively.  This question came to my mind after reading  which made me curious again.  The for here:   for(p=0;p+=(a&amp;1)*b,a!=1;a&gt;&gt;=1,b&lt;&lt;=1);   In the middle condition there is a comma separating the two pieces of code, what does this comma do? The comma on the right side I understand as it makes both a&gt;&gt;=1 and b&lt;&lt;=1.   But within a loop exit condition, what happens? Does it exit when p==0, when a==1 or when both happen?  It would be great if anyone could help me understand this and maybe point me in the direction of a full for loop syntax description.
117193
Do we need to be careful when comparing a double value against zero?  if ( someAmount &lt;= 0){ ..... }
54737
"Voted on 600 questions and has better than 3:1 answer/question vote ratio" is the current text.  "Voted on 600 questions and 25% or more of total votes are on questions" is my proposed text.  (Or should it read "or less"?  I'm still not completely sure what is intended.)  "Better" in the original doesn't indicate which way is preferred (and it's not clear to me one way or the other is better, merely that a certain threshold is the requirement for this badge).  This is even slightly shorter, in both characters and as displayed for me in a proportional font, which should help for a badge with one of the longest current descriptions.
25130
Of course most languages have library functions for this, but suppose I want to do it myself.  Suppose that the float is given like in a C or Java program (except for the 'f' or 'd' suffix), for example "4.2e1", ".42e2" or simply "42". In general, we have the "integer part" before the decimal point, the "fractional part" after the decimal point, and the "exponent". All three are integers.  It is easy to find and process the individual digits, but how do you compose them into a value of type float or double without losing precision?  I'm thinking of multiplying the integer part with 10^n, where n is the number of digits in the fractional part, and then adding the fractional part to the integer part and subtracting n from the exponent. This effectively turns 4.2e1 into 42e0, for example. Then I could use the pow function to compute 10^exponent and multiply the result with the new integer part. The question is, does this method guarantee maximum precision throughout?  Any thoughts on this?
86674
exam package enables the possibility to use and define \half as to for instance consider .5. However I have not seen any way of implementing .75 and .25 in case I want a part or question to have that value.  Is it possible? In case yes can you give me an example and how I can have the correct sum of points per question?  Edit: MWE included  \documentclass[11pt, addpoints, twoside, a4paper]{exam}  \begin{document}  \begin{questions}  \renewcommand*\half{.5} \question[0\half] This question is 0.5 points  \renewcommand*\half{.25} \question[1\half] This question is 1.25 points  \renewcommand*\half{.5} \question[1\half] This question is 1.5 points  \end{questions}  Total points with addpoints: \numpoints~(3.5)  Total points real count: 3.25  I don't know how to define quarters, etc. so I can easily define the points in my questions without having to renew \texttt{half} command, and also having the final sum properly done.  \end{document}
15383
I have defined the following command to typeset 'C++':  \newcommand{\Cpp}{C\raisebox{-.23ex}{\texttt{++}}}   Using the command in a paragraph works as expected. However, I can't use it in a section title. I seems like it has something to do with \raisebox.  Here an mwe:  \documentclass[11pt]{article}  \newcommand{\Cpp}{C\raisebox{-.23ex}{\texttt{++}}}  \begin{document}     \section{\Cpp} % doesn't work! because of \raisebox ? \Cpp-Compiler \end{document}   How can I redefine the \Cpp command to work in a section title?
7945
What is the difference between &gt;&gt; and &gt;&gt;&gt; in verilog/system verilog? I know that == tests for only 1 and 0, while === tests for 1, 0, X, Z. So how is that similar to the shift operator?
67106
Is there a function to round a float in C or do I need to write my own?       float conver = 45.592346543;   I would like to round the actual value to one decimal place, conver = 45.6.
44888
I'm reading The C++ Programming Language and in it Stroustrup states that the int value of a char can range from 0 to 255 or -127 to 127, depending on implementation. Is this correct? It seems like it should be from -128 to 127.  If not, why are their only 255 possible values in the second implementation possibility, not 256.
78827
My brother recently started learning C++. He told me a problem he encountered while trying to validate input in a simple program. He had a text menu where the user entered an integer choice, if they entered an invalid choice, they would be asked to enter it again (do while loop). However, if the user entered a string instead of an int, the code would break. I read various questions on stackoverflow and told him to rewrite his code along the lines of:    #include&lt;iostream&gt; using namespace std;  int main() {     int a;     do     {     cout&lt;&lt;"\nEnter a number:"     cin&gt;&gt;a;         if(cin.fail())         {             //Clear the fail state.             cin.clear();             //Ignore the rest of the wrong user input, till the end of the line.             cin.ignore(std::numeric_limits&lt;std::streamsize&gt;::max(),\                                                     '\n');         }     }while(true);     return 0; }   While this worked ok, I also tried a few other ideas: 1. Using a try catch block. It didn't work. I think this is because an exception is not raised due to bad input. 2. I tried if(! cin){//Do Something} which didn't work either. I haven't yet figured this one out. 3. Thirdly, I tried inputting a fixed length string and then parsing it. I would use atoi(). Is this standards compliant and portable? Should I write my own parsing function? 4. If write a class that uses cin, but dynamically does this kind of error detection, perhaps by determining the type of the input variable at runtime, would it have too much overhead? Is it even possible?  I would like to know what is the best way to do this kind of checking, what are the best practices?  I would like to add that while I am not new to writing C++ code, I am new to writing good standards compliant code. I am trying to unlearn bad practices and learn the right ones. I would be much obliged if answerers give a detailed explanation.  EDIT: I see that litb has answered one of my previous edits. I'll post that code here for reference.  #include&lt;iostream&gt; using namespace std;  int main() {     int a;     bool inputCompletionFlag = true;     do     {     cout&lt;&lt;"\nEnter a number:"     cin&gt;&gt;a;         if(cin.fail())         {             //Clear the fail state.             cin.clear();             //Ignore the rest of the wrong user input, till the end of the line.             cin.ignore(std::numeric_limits&lt;std::streamsize&gt;::max(),\                                                     '\n');         }         else         {             inputCompletionFlag = false;         }     }while(!inputCompletionFlag);     return 0; }   This code fails on input like "1asdsdf". I didn't know how to fix it but litb has posted a great answer. :)
83102
Let's examine these two statements:  IF (CONDITION 1) OR (CONDITION 2) ...  IF (CONDITION 3) AND (CONDITION 4) ...   If CONDITION 1 is TRUE, will CONDITION 2 be checked? If CONDITION 3 is FALSE, will CONDITION 4 be checked?  What about conditions on WHERE: does the SQL Server engine optimize all conditions in a WHERE clause? Should programmers place conditions in the right order to be sure that the SQL Server optimizer resolves it in the right manner?     ADDED:  Thank to Jack for link, surprise from t-sql code:  IF  1/0 = 1 OR 1 = 1       SELECT 'True' AS result ELSE       SELECT 'False' AS result   IF  1/0 = 1 AND 1 = 0       SELECT 'True' AS result ELSE       SELECT 'False' AS result   There is not raise a Divide by zero exception in this case.  CONCLUSION:  If C++/C#/VB has short-circuiting why can't SQL Server have it?     To truly answer this let's take a look at how both work with   conditions. C++/C#/VB all have short circuiting defined in the   language specifications to speed up code execution. Why bother   evaluating  N OR conditions when the first one is already true or M   AND conditions when the first one is already false.      We as developers have to be aware that SQL Server works differently.   It is a cost based system. To get the optimal execution plan for our   query the query processor has to evaluate every where condition and   assign it a cost. These costs are then evaluated as a whole to form a   threshold that must be lower than the defined threshold SQL Server has   for a good plan. If the cost is lower than the defined threshold the   plan is used, if not the whole process is repeated again with a   different mix of condition costs. Cost here is either a scan or a seek   or a merge join or a hash join etc... Because of this the   short-circuiting as is available in C++/C#/VB simply isn't possible.   You might think that forcing use of index on a column counts as short   circuiting but it doesn't. It only forces the use of that index and   with that shortens the list of possible execution plans. The system is   still cost based.      As a developer you must be aware that SQL Server does not do   short-circuiting like it is done in other programming languages and   there's nothing you can do to force it to.