Ask a question

How Can I Write The Following Expression In C In Visual Studio

How do I do Pure C programming with Visual Studio 2017? I want to relearn C.

Microsoft Visual Studio includes a C compiler, though it is fairly well hidden and is of rather poor quality as far as language feature support goes. As recently as 2012, they had no plans to support C at all (the Microsoft C compiler was frozen at doubly-archaic C89 language support), but starting with Visual Studio 2015 its C compiler now implements elements of C99, so there is hope. If you wish to learn modern C, I strongly recommend a compiler that supports C11 language features: gcc, clang, intel, etc.Nevertheless, to compile C in Visual Studio 2017, you’d have to do the following:Install Visual Studio C++ (that’s where they are hiding the C compiler)Create New Project -> Visual C++ -> Win32 Console ApplicationClick “Next” (not “Finish”)Choose “Console Application”, and “Empty Project”Click “Finish”On the left, right click on Source Files, choose Add, New Item…Type in a file name that ends with .c. The options displayed are “C++ File (.cpp)” and “Header File (.h)”. Ignore that and type “yourfilename.c”.Type your C code and use Ctrl-F5 to compile and executeNote other answers so far tell you how to create a C++ program in Visual Studio. That’s a different programming language using a different compiler. Here’s an example of a C program that I just executed in my Visual Studio 2017. It won’t compile if you put it in a file with the .cpp extension:#include

int main(void)
int* p = (int[]) { 1, 2 };
printf("%d\n", p[0]);
I followed the steps above, pressed Ctrl-F5 and got the console window with the expected output:1
Press any key to continue . . .
You can also use the /TC option to treat any file as C source, or in fact, use the command line compiler: cl /TC source.c

Write expression that causes code to print "Equal" if the value of sensorReading is "close enough" to targetValue. Else print "Not equal"?

import java.lang.Math;

public class SensorThreshold {
public static void main(String[] args) {
double targetValue = 0.3333;
double sensorReading = 0.0;

sensorReading = 1.0 / 3.0;

if (/* Your solution goes here */) {
else {
System.out.println("Not equal");


I can get the first test the program uses to output the desired result but it goes through several test with different sets of numbers and I can't get them to be correct. So any help would be appreciated. The program I'm using is called Zybooks.

Can I use a regex in Visual Studio 2008 to program in C?

You can use PCRE (Perl Compatible Regular Expressions) C library. [1]It’s C library with regex function in it, so you can statically or dynamically linked to your C program.Footnotes[1] PCRE - Perl Compatible Regular Expressions

What does an expression involving multiple post/pre decrement/increment operators evaluate to in C and C++?

A2AThe answer from Sergey Zubkov is most correct.Specifically, in the C standard in section, paragraph 3, it clearly states that the expression is unsequenced.The important part of this is covered in note 13:ISO/IEC 9899:201xThe executions of unsequenced evaluations can interleave. Indeterminately sequenced evaluations cannot interleave, but can be executed in any order.Sequence points are described in detail in the C standard, in the informational section in annex C, located at the end of the standards document.Because the values are computed without being ordered before the addition, the value will be anywhere between 18 and 24, depending on the compiler being used, and the option flags — primarily those controlling code optimization.It should be noted that Turbo-C has not been actively developed since 1990 — more than a quarter of a century ago — and even their web site calls it antique software: Antique Software: Turbo C version 2.01.While this won’t change the answers regarding sequence points, it does mean that the compiler is grossly out of date, and its behaviour should not be take as being standards compliant for more modern standards.

Case Expression not constant?

Your command variable is a char. "A" is not a char, it's a string literal. In C/C++ string literals are not constants.

But chars are, so this is an easy fix.
Change "A" to 'A'. 'A' is a char, and it is a constant.

Do the same for "B", "C" and "D".

What does 'expression: list iterators incompatable' mean in c++? I hate the STL!!!

I ran your code under the debugger with a simple list of 3 numbers, 3,2,1 and hit the same error.
It's a debug assertion, so I hit retry to jump into the debugger to see what code threw the assert.

It's this ugly bit of code in file list, line 289:
bool operator==(const _Myiter& _Right) const
{// test for iterator equality
if (this->_Getcont() == 0
|| this->_Getcont() != _Right._Getcont())
{// report error
_DEBUG_ERROR("list iterators incompatible");

Looking back further on the stack, you can see it was called from this line of code:
while(first != last)

So...there's something about the first or last iterator this code doesn't like.

I ran again with a breakpoint on that while statement, with first and last in the watch window.
The first time the loop executes, first and last are fine, each time through the loop (it's sort of a guess that last is right, since it's the end of the list, but first was rational). The next time you get to the loop, first is junk. So it's the caller that's at fault, on the second call, first is invalid.
So backtrack to the caller:
maxVal = maxIter(passIter, aList.end());

With a breakpoint on that line, and passIter in the watch window, it became obvious. (It should have been obvious just by looking, but it's been so many years since I've struggled with the STL, it didn't jump out and hit me).

You're violating a basic rule of iterators: You can't modify the thing you are iterating over.
Here's what happens. Remember, my list is 3,2,1.
passIter starts out at 3.
maxVal gets set to 3. passIter is still 3 at this point.
you push_front 3. passIter is still 3.
you erase 3. BOOOM. You just erased the node your iterator is pointing to.
You can step into that erase code and see what it does. You'll see that it calls a function called _Orphan_ptr. And the comment in Orphan says:
// orphan iterators with specified node pointers

That should answer your question. Don't ask me how to fix it, I hate the STL ;-)

ETA: Drats, Oops beat me by 4 minutes. I gotta learn to write shorter answers!!!

Write a program to evaluate the fuel consumption of a car. Have the user input the miles on the car’s odometer?

So... what's you question? Because we're not here to do your homework for you...

Is C#, C++ and Java on Microsoft Visual Studio Code worth learning as a 15 year old in 2019?

Sure the languages are worth learning. I would not recommend starting off with C or C++, but C# is a neat one for starters. Java is also a pretty good one, but on Windows, I'd still recommend C# over Java. Both of them will also help you get used to a C-like syntax.However when starting to learn the language, I recommend you to start off with some small tutorials. After copying the code from the tutorial, ask yourself further which expression causes what. To understand the expression, the language and your compiler better, edit the code you copied, e.g. leave out the semicolon at the end or do other small changes and see what happens then. A basic understanding of the language and the compiler will help you understanding specific errors better later on.When you habe done the small codes and grasped some basic input and output on the console as well as which types you may use when and how you calculate, make up some individual problems for yourself to solve them. Before coding, take out your pen and model your solution on a paper, feel free to use any kind of graphics to visualize it for yourself. Thenafter try to implement that solution in code.While coding, don't just write the code, but also leave comments explaining what the specific lines are for. No need to comment the very obvious ones, but think of it like you would want to look into the same code after a decade again, so you'd need to leave some marks for you to remember everything. Also give attention to the indentation and don't write too long lines to increase readability. Those are some Good Coding rules that you will probably learn in none of the tutorials, but it's a fundamental base for any programmer IMO.Good luck on your journey!