answersLogoWhite

0

It is not clear what do you mean by 'logical error', but perhaps an example will help:

int main (void)

{

FILE *f= fopen ("foobar.txt", "r");

if (f) printf ("couldn't open foobar.txt for reading");

fclose (f);

}

corrected version:

int main (void)

{

FILE *f= fopen ("foobar.txt", "r");

if (f==NULL) {

printf ("couldn't open foobar.txt for reading");

return 0;

}

fclose (f);

}

Logical error can be generated by using the #error directive. This directive doesn't allows the program to run, in certain conditions. An error message has been generated by the compiler because of this preprocessor directive.

e.g.

#define M 10

#if M!=10

#error M must be 10

#endif

in this case no error mesage will be generated because M is equal to 10

#define M 11

#if M!=10

#error M must be 10

#endif

in this case, as M is not equal to 10 error message will be generated by the compiler and the message will be M must be 10.

User Avatar

Wiki User

14y ago

What else can I help you with?

Related Questions

What is difference between syntx error and logical error?

A syntax error is when you break the grammar rules of the language, such as forgetting to terminate a C++ statement with a semi-colon. A logical error is when your code does not perform as expected, typically due to an assumption that proves to be incorrect.


What is a logical error?

One of your drives has an error (known or unknown)


Which of these is an error in reasoning?

a logical fallacy


What is a logical drive error?

One of your drives has an error (known or unknown)


Whenever you try to create programs in C but when you would run them it would always make an error on unable to create an output file?

AnswerPlease visit here http://techgulf.blogspot.com/2011/02/fatal-error-unable-to-create-output.htmlhope it will help you


What has the author C A Qadir written?

C. A. Qadir has written: 'Logical positivism' -- subject(s): Logical positivism


What are the logical errors in c plus plus programs?

A logical error is an error that violates a class invariant or a logical precondition. Logic errors are typically detected at compile time and typically throw a derivative of std::logic_error exception. By contrast, runtime exceptions throw a derivative of std::runtime_error. Both classes can be found in <stdexcept>. The built-in std::logic_error types are: domain_error, invalid_argument, length_error, out_of_range and future_error.


What is the difference between a compilation error and logic error?

errors which come during compilation is known as compilation error. here we get syntax errors only not logical errors like division by zero. logical error occur during run time example:if you write a program for division with zero you will not get compilation error but during execution you will error


How many types of logical operators in c only?

There are three logical operators in C; AND (&), OR (|), and NOT (^). These are the bitwise versions. The combinatorial versions are &&, , and !.


Is it logical to modulate from G Minor to C Major?

I think it is pretty logical>


A statement that contains an error in logic is?

Technically speaking, an "error in logic" (a fallacy) is a case where the premises do not properly support the argument made. Fallacies are not to be confused with factual errors, wherein the error is caused by a lack of proper information.


How do you create logical partitions?

For this purpose you have to have unlocated space. Then in "Computer Management->Disk Management", right click, create exteneded partion. And in the extended partion you will be able to create a logical partion(s).