598 Answered Questions for the topic C++
C++
05/06/19
What's the rationale for null terminated strings?
As much as I love C and C++, I can't help but scratch my head at the choice of null terminated strings:* Length prefixed (i.e. Pascal) strings existed before C* Length prefixed strings make several...
more
C++
05/01/19
unsigned int vs. size_t?
I notice that modern C and C++ code seems to use `size_t` instead of `int`/`unsigned int` pretty much everywhere - from parameters for C string functions to the STL. I am curious as to the reason...
more
C++
04/30/19
How to avoid "if" chains?
Assuming I have this pseudo-code: bool conditionA = executeStepA(); if (conditionA){ bool conditionB = executeStepB(); if (conditionB){ bool conditionC =...
more
C++
04/28/19
Are global variables bad?
In C/C++, are global variables as bad as my professor thinks they are?
C++
04/28/19
What's the purpose of using braces (i.e. {}) for a single-line if or loop?
I'm reading some lecture notes of my C++ lecturer and he wrote the following: > 1. Use Indentation // OK> 2. Never rely on operator precedence - Always use parentheses // OK > 3. Always...
more
C++
04/24/19
return statement vs exit() in main()?
Should I use `exit()` or just `return` statements in `main()`? Personally I favor the `return` statements because I feel it's like reading any other function and the flow control when I'm reading...
more
04/20/19
What is C++ syntax?
What is Linux’s native GUI API?
I hope this doesn’t come across as a stupid question but it’s always something I have wondered. Both Windows (Win32 API) and OS X (Cocoa) have their own APIs to handle windows, events and other OS...
more
C++
03/27/19
Why use apparently meaningless do-while and if-else statements in macros?
In many C/C++ macros I'm seeing the code of the macro wrapped in what seems like a meaningless `do while` loop. Here are examples. #define FOO(X) do { f(X); g(X); } while (0) #define FOO(X)...
more
C++
03/27/19
How do you set, clear, and toggle a single bit?
How do you set, clear, and toggle a bit in C/C++?
C++
03/27/19
What's this =! operator?
I was surprised by this code: if (a =! b) { // let it be on false ... }But `a` is never assigned by a value. What's this operator about?
C++
03/27/19
How to avoid overflow in expr. A * B - C * D?
I need to compute an expression which looks like:`A*B - C*D`, where their types are: `signed long long int A, B, C, D;`Each number can be really big (not overflowing its type). While `A*B` could...
more
C++ Logic
03/19/19
C++ interview preparation?
I have a Phone interview coming up next with with a company which works in financial software industry. The interview is mainly going to be in C++ and problem solving and logic. Please tell me the...
more
C++
03/19/19
What is runtime polymorphism in C++?
C++
03/18/19
Single quotes vs. double quotes in C or C++?
When should I use single quotes and double quotes in C or C++ programming?
03/18/19
What happens when you logical not a float?
I assume this just returns an int. Is there anything else going on I should be aware of? C/C++ differences?
float a = 2.5;
!a; // What does this return? Int? Float?
What is Linux’s native GUI API?
I hope this doesn’t come across as a stupid question but it’s always something I have wondered. Both Windows (Win32 API) and OS X (Cocoa) have their own APIs to handle windows, events and other OS...
more
C++
03/18/19
Why use pointers?
I know this is a really basic question, but I've just started with some basic C++ programming after coding a few projects with high-level languages. Basically I have three questions: 1. Why use...
more
C++
02/14/19
Problem solving process
Draw a Problem Analysis Chart (PAC), Interactivity chart ,IPO chart, Algorithmand flowchart for the following problems1. A painter wants to know the amount of paint needed to paint only the walls...
more
C++ Programming
02/01/19
C++ changing the char of Vector <string>
void encodeUpper (vector <string> &book, int &cipher){
string word;
char asciiNum;
for(int i=0;i<book.size();i++){
if...
more
C++
10/23/18
what is the code?
A bus line has busses with 30 gallon tanks. that it uses to travel to different cities. The company needs you to write a c++ program that will allow the clerk to input the roundtrip mileage to and...
more
10/08/18
tricky c++ if else question
Why will it print the bold statements? what about Hi-5 "
#include <iostream>using namespace std;int main (){ if ((4 < 2 ) && (3 == 3)) cout << "Hi-2 "; else if (3==3) cout...
more
10/08/18
if else confusing problem?
In this program no matter how many times i run it it wont print out the statement in bold.
shouldnt it print evert statement after else?
it will only print "HI-6"
#include...
more
07/31/18
Write a C++ if statement
Write a C++ if statement that displays the message “The score is invalid.” if the variable score is outside the range 0 through 100.*Assume the variable score has already been declared and...
more
C++ Psuedo Code
07/31/18
Convert the following C++ code statements to the equivalent C++ for loop code statements
14. Convert the following C++ code statements to the equivalent C++ for loop code statements:int count = 10;while (count <= 100){cout << "The count is " << count << endl;count++;}
more
Still looking for help? Get the right answer, fast.
Ask a question for free
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Find an Online Tutor Now
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.