Interview answers verified by specialists.

Find interview questions and answers on this website:

See right interview answers on 30 common job interview questions

How can a program be made to print the line number where an error occurs?

The ANSI C standard includes a predefined macro named __LINE__ that can be used to insert the current
source code line number in your program. This can be a very valuable macro when it comes to debugging
your program and checking for logic errors. For instance, consider the following portion of code:

int print_document(char* doc_name, int destination)
     switch (destination)
          case TO_FILE:
          case TO_SCREEN:
          case TO_PRINTER:
               printf("Logic error on line number %d!\n", __LINE__);

If the function named print_document() is passed an erroneous argument for the destination parameter
(something other than TO_FILE, TO_SCREEN, and TO_PRINTER), the default case in the switch statement traps
this logic error and prints the line number in which it occurred. This capability can be a tremendous help
when you are trying to debug your program and track down what could be a very bad logic error.

Do you know that?

Always sketch out your ideas first before designing on the computer. Next


Getting payments for Freelancers
1. Read how to register and get earned money

2. Open account within 5 minPayoneer sing up to get free $25