Home c++ C4703 error - Potentially uninitialized local variable-pointer "Q"

C4703 error – Potentially uninitialized local variable-pointer “Q”

Author

Date

Category

Dan snippet code:

int a [5] = {1,3, -5,4,2}, n = 5, * p, * q, a = 0, b = 0, c = 0;
for (p = a + n-1; p & gt; = a; p--)
  IF (P & GT; A + 1 & amp; & amp; p & lt; a + 3)
        q = p;
   a = * q; b = * (Q-1);

Task Such:
Calculate the values ​​of all variables in a specified fragment of the program when running each line.

But when I try to run debugging, it gives such a mistake:

C4703-Potentially uninitialized local variable indicator “Q”

What is the problem and how can it be solved?


Answer 1

Everything is simple, you did not initialized p and q

Replace the initialization string, to such:

int a [5] = {1,3, -5,4,2}, n = 5, * p = nullptr, * q = nullptr, a = 0, b = 0, c = 0 ;

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions